-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem36.cpp
More file actions
63 lines (57 loc) · 1.84 KB
/
Copy pathProblem36.cpp
File metadata and controls
63 lines (57 loc) · 1.84 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
/*
Krishna Mohan
Project Euler - Problem 36
Date: 3/22/2015
*/
#include <bits/stdc++.h>
using namespace std;
#define fo(i, n) for(int (i)=0;(i)<(n); (i)++)
#define MAX 1000001
#define LIM 50
bool isPalin(int n[LIM], int sz)
{
for(int i=0,j=sz-1;i<j;i++,j--)
{
if(n[i]!=n[j])
return false;
}
return true;
}
int main() {
int dnum[LIM], bnum[LIM], dlen, blen, num;
long long sum=0;
for(int i=1;i<MAX;i++)
{
dlen=0;
num=i;
while(num)
{
dnum[dlen++]=num%10;
num/=10;
}
num=i;
blen=0;
while(num)
{
bnum[blen++]=num%2;
num/=2;
}
/*if(i==585)
{
cout<<blen<<" : "<<dlen<<endl;
for(int k=0;k<dlen;k++)
cout<<dnum[k];
cout<<endl;
for(int k=0;k<blen;k++)
cout<<bnum[k];
cout<<endl;
}*/
if(isPalin(dnum, dlen) && isPalin(bnum, blen))
{
//cout<<i<<endl;
sum+=i;
}
}
cout<<"Ans: "<<sum<<endl;
return 0;
}