#P8635. [蓝桥杯 2016 省 AB] 四平方和
[蓝桥杯 2016 省 AB] 四平方和
Problem Description
The Four Squares Theorem, also called Lagrange's theorem, states:
Every positive integer can be written as the sum of squares of at most positive integers.
If we also allow , then it can be written as the sum of squares of exactly numbers.
For example:
.
.
For a given positive integer, there may be multiple representations as a sum of squares.
You need to sort the four numbers so that .
Then sort all possible representations in ascending order using as a combined key, and finally output the first representation.
Input Format
The input is a positive integer .
Output Format
Output non-negative integers in increasing order, separated by spaces.
5
0 0 1 2
12
0 2 2 2
773535
1 1 267 838
Hint
Time limit: 3 seconds, 256M. Lanqiao Cup 2016, the 7th provincial contest.
Lanqiao Cup 2016 provincial contest, Group A Problem H (Group B Problem H).
Translated by ChatGPT 5