-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththree_sqare.cpp
More file actions
99 lines (81 loc) · 1.98 KB
/
three_sqare.cpp
File metadata and controls
99 lines (81 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
using namespace std;
struct square {
int sq;
int a;
int b;
} s [50000];
bool isPerfectSquare (int p)
{
int sqr = sqrt (p);
if ( sqr * sqr == p ) return true;
return false;
}
int main ()
{
int testCase;
scanf ("%d", &testCase);
int len_s = 0;
for ( int i = 0; i < 225; i++ ) {
for ( int j = i; j < 225; j++ ) {
s [len_s].sq = i * i + j * j;
s [len_s].a = i;
s [len_s].b = j;
len_s++;
}
}
while ( testCase-- ) {
int k;
scanf ("%d", &k);
//printf ("%d\n", len_s);
bool printed = false;
for ( int i = 0; i < len_s; i++ ) {
if ( isPerfectSquare (k - s [i].sq) ) {
int output [3];
output [0] = s [i].a;
output [1] = s [i].b;
output [2] = (int) sqrt (k - s [i].sq);
sort (output, output + 3);
printf ("%d %d %d\n", output [0], output [1], output [2]);
printed = true;
break;
}
}
if ( !printed ) printf ("-1\n");
}
return 0;
}
/*int main()
{ int n = 50000 ;
pair <int ,pair<int,int>> ans[n];
int sq = sqrt(n);
for(int i =0 ; i< n ;i++)
ans[i].first = -1 ;
for(int i = 0 ; i <= sq ; i++)
{
for(int j = 0 ; j <= sq ; j++)
{
for(int k = 0 ; k <= sq ; k++)
{
if(i*i+j*j+k*k>n) break;
if(ans[i*i+j*j+k*k].first==-1)
ans[i*i+j*j+k*k] = {i,{j,k}};
}
}
}
int t ;
cin>>t;
while(t--)
{
int N;
cin>>N;
if(ans[N].first==-1)
cout<<-1<<endl;
else
cout<<ans[N].first<<" "<<ans[N].second.first<<" "<<ans[N].second.second<<endl;
}
return 0;
}
*/