-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUva256.cpp
More file actions
60 lines (53 loc) · 1 KB
/
Copy pathUva256.cpp
File metadata and controls
60 lines (53 loc) · 1 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
#include <iostream>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
using namespace std;
int Arr[100000];
pair<int,int> getTwoNumbers(int N){
string temp1="";
string temp2="";
int c=N/2;
int incr=c;
for(int i=0;i<c;i++){
temp1+=to_string(Arr[i]);
temp2+=to_string(Arr[incr]);
incr++;
}
int num1=atoi(temp1.c_str());
int num2=atoi(temp2.c_str());
return make_pair(num1,num2);
}
void calculate(int N){
string res="";
for(int i=0;i<N;i++){
res+=to_string(Arr[i]);
}
int number=atoi(res.c_str());
pair<int,int> nums=getTwoNumbers(N);
if(pow(nums.first + nums.second,2)==number){
cout<<res<<endl;
}
}
void gen(int n,int N){
if(n>=N){
calculate(N);
return;
}
for(int i=0;i<=9;i++){
Arr[n]=i;
gen(n+1,N);
}
}
int main()
{
int N;
while(cin>>N){
gen(0,N);
}
return 0;
}