-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path00256 Quirksome Squares.cpp
61 lines (57 loc) · 1.54 KB
/
00256 Quirksome Squares.cpp
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
#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
#define pb push_back
using namespace std;
struct Quirk {
vector <string> out;
Quirk(ll n) {
ll maxi = 0, aux = 1;
for(ll i = 0; i < n; i++) {
maxi += (9*aux);
aux *= 10;
}
maxi = sqrt(maxi);
//cout << maxi << endl;
for(ll num = 0; num <= maxi; num++) {
ll i = num * num;
ll a = 0, b = 0;
aux = 1;
string resp = "", trueResp = "";
for(ll j = 0; j < (n/2); j++) {
if(i == 0) break;
a += (i % 10) * aux;
resp += (char)('0' + (i % 10));
aux *= 10;
i /= 10;
}
aux = 1;
for(ll j = 0; j < (n/2); j++) {
if(i == 0) break;
b += (i % 10) * aux;
resp += (char)('0' + (i % 10));
aux *= 10;
i /= 10;
}
if((a + b) == num) {
while(resp.size() < n) resp += '0';
for(ll i = n - 1; i >= 0; i--) trueResp += resp[i];
out.pb(trueResp);
}
}
}
void show() {
for(auto val : out) {
cout << val << endl;
}
}
};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
vector<Quirk> table{Quirk(2), Quirk(4), Quirk(6), Quirk(8)};
ll n;
while(cin >> n) {
table[(n/2)-1].show();
}
}// 00256 Quirksome Squares.cpp