forked from SharmaManish/Spoj
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathACPC10B.cpp
More file actions
70 lines (48 loc) · 1.66 KB
/
ACPC10B.cpp
File metadata and controls
70 lines (48 loc) · 1.66 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
#include<iostream>
#include<stdio.h>
#include<vector>
using namespace std;
long long sumOfSquares(long long x)
{
long long e=0;
while(x!=0)
{
e=e+(x%10)*(x%10);
x=x/10;
}
return e;
}
int main()
{
long long A,B;
while(true)
{
scanf("%lld",&A);
scanf("%lld",&B);
if(A==0 && B==0)
break;
int count=0;bool flag=false;
long long int C=A,D=B,E,F;
while(C!=4 && C!=16 && C!=37 && C!=58 && C!=89 && C!=145 && C!=42 && C!=20 || D!=1 )
{
E=C,F=D;
C=sumOfSquares(C);
D=sumOfSquares(D);
if(C!=E && D!=F)
count=count+2;
else if((D==F && C!=E) || (D!=F && C==E))
count=count+1;
if(C==D)
{
flag=true;
break;
}
}
if(flag)
printf("%lld %lld %d\n",A,B,count);
else
printf("%lld %lld 0\n",A,B);
}
system ("pause");
return 0;
}