-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprob92.cpp
60 lines (58 loc) · 891 Bytes
/
prob92.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
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
long long digitSquare(long long num)
{
long long ans = 0;
while(num > 0)
{
ans = ans + (num%10)*(num%10);
num = num/10;
}
return ans;
}
int main()
{
int* array = new int[10000000];
//0 for one
//1 for 89
//2 intially
fill(array,array+10000000,2);
array[0] = 0;
array[88] = 1;
for(int i=0;i < 10000000; i++)
{
if(array[i] == 2)
{
vector<int> v;
int k = i+1;
while(k != 1 && k != 89)
{
v.push_back(k);
k = digitSquare(k);
if(array[k-1] != 2)
{
break;
}
}
int awe = array[k-1];
if (k == 1 )
awe = 0;
else if(k == 89)
awe = 1;
for(int kl = 0; kl < v.size() ; kl++)
{
array[v[kl]-1] = awe;
}
}
}
int count = 0;
for (int i = 0; i < 10000000; ++i)
{
if(array[i] == 1)
count++;
}
cout<<count<<endl;
return 0;
}