#include<iostream> #include<stdio.h> #include<vector> #include<map> #include<math.h> #include<string> #include<string.h> #include<algorithm> using namespace std; int s(unsigned long long int x) { int sum=0,a=0; for(;x>0;x/=10) { a=x%10; sum+=(a*a); } return sum; } int main() { unsigned long long int k=0,a=0,b=0,kk=0,x=10; cin>>k>>a>>b; a=a+k-a%k; for (int i=1;x<b;i++,x*=10) { //cout<<81*i*k<<" "<<x-1<<"\n"; if(81*i*k<x-1){b=x;break;} } //cout<<a<<" "<<b<<"\n"; for(;a<=b;a+=k) { if(s(a)*k==a){kk++;} } cout<<kk; 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 37 38 | #include<iostream> #include<stdio.h> #include<vector> #include<map> #include<math.h> #include<string> #include<string.h> #include<algorithm> using namespace std; int s(unsigned long long int x) { int sum=0,a=0; for(;x>0;x/=10) { a=x%10; sum+=(a*a); } return sum; } int main() { unsigned long long int k=0,a=0,b=0,kk=0,x=10; cin>>k>>a>>b; a=a+k-a%k; for (int i=1;x<b;i++,x*=10) { //cout<<81*i*k<<" "<<x-1<<"\n"; if(81*i*k<x-1){b=x;break;} } //cout<<a<<" "<<b<<"\n"; for(;a<=b;a+=k) { if(s(a)*k==a){kk++;} } cout<<kk; return 0; } |