UVa 11342 - Three-square

Summary
A positive integers K (0 < K <= 50000). For each test case print a line formatted like this: "a b c". Where a <= b <= c and K = a^2 + b^2 + c^2. If there is more than one possible answer, print the one that comes first lexicographically. If expression in three squares of non-negative integers do not exist print "-1" (see examples).

Explanation
Pre-calculate a^2 + b^2 and also store a, b. For each input n, if n - i^2 ( 0<=i<=223) in the table, print the answer. If not, print "-1".

Input
3 13 15 17

Output
0 2 3 -1 0 1 4