#include <iostream> using namespace std; long f(long x) { long temp=0; while(x>1) { int a=x%10; x=x/10; temp+=a*a; } return temp; } int main() { long k,a,b; cin>>k>>a>>b; int n=0; for (long i=a;i<b;i++) { if(i%k==0) { if(i==f(i)*k) { n++; } } } cout<<n; return 0; }
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 | #include <iostream> using namespace std; long f(long x) { long temp=0; while(x>1) { int a=x%10; x=x/10; temp+=a*a; } return temp; } int main() { long k,a,b; cin>>k>>a>>b; int n=0; for (long i=a;i<b;i++) { if(i%k==0) { if(i==f(i)*k) { n++; } } } cout<<n; return 0; } |