[ create a new paste ] login | about

Link: http://codepad.org/S05IoyBJ    [ raw code | fork ]

C++, pasted on Aug 3:
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<cmath>
using namespace std;

int main()
{
	vector<int>res;
	int tc, n, flag;
	cin >> tc;
	while (tc--)
	{
		flag = 0;
		res.clear();
		cin >> n;
		if (n % 8 == 7)
			cout << "-1" << endl;
		else
		{
			int s = sqrt(n);
			for (int i = 0; i <= s; i++)
			{
				for (int j = i; j <= s; j++)
				{
					for (int q = j; q <= s; q++)
					{
						if (i*i + j*j + q*q == n)
						{
							res.push_back(i);
							res.push_back(j);
							res.push_back(q);
							flag = 1;
							break;
						}
						if (flag == 1)
							break;
						else
							continue;
					}
					if (flag == 1)
						break;
				}
				if (flag == 1)
					break;
			}
			for (int i = 0; i < res.size(); i += 3)
			{
				cout << res[i] << " " << res[i + 1] << " " << res[i + 2] << endl;
			}
		}
	}
	return 0;
}


Create a new paste based on this one


Comments: