
three squres
By: a guest on
Aug 19th, 2012 | syntax:
C++ | size: 0.94 KB | hits: 16 | expires: Never
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
int main ()
{
double sum,i ,h,j ,sum2;
vector<double> v;
int test_cases;
bool found=false;
cin>>test_cases;
for(int t=0;t<test_cases;t++)
{
cin>>sum;
for( i=0;i<10;i++)
{
for( j=0;j<10 ;j++)
{
for( h=0;h<10 ;h++)
{
sum2=(pow(i,2)+pow(j,2)+pow(h,2));
if(sum2==sum)
{
v.push_back(i);
v.push_back(j);
v.push_back(h);
found=true;
break;
}
}
if(found==true)
{
break;
}
}
if(found==true)
{
break;
}
}
sort(v.begin(),v.end());
if(found==false)
{
cout<<-1;
}
else
{
for(int n=0;n<v.size();n++)
{
cout<<v[n];
if(n!=v.size()-1)
{
cout<<" ";
}
}
}
cout<<endl;
v.clear();
found=false;
}
return 0;
}