-
Notifications
You must be signed in to change notification settings - Fork 0
/
demented
37 lines (36 loc) · 821 Bytes
/
demented
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
#include<iostream>
#include<cmath>
using namespace std;
int main() {
int t,a,b,temp,sum,d,count;
cin>>t;
while(t--) {
cin>>a>>b;
count = 0;
for(int i=a;i<=b;i++) {
temp = i;
sum = 0;
int k=700;
while(k--) {
while(temp != 0) {
d = temp%10;
sum = sum + pow(d,2);
temp/=10;
}
if(sum == 1){
//cout<<i<<" ";
count++;
break;
}
else if(sum == i){
break;
}
// cout<<sum<<" ";
temp=sum;
sum=0;
}
}
cout<<count<<endl;
}
return 0;
}