#include <iostream> using namespace std; int main() { long long int k,a,b; int h=0,i,s[10]; for(i=0;i<10;i++) s[i]=i*i; cin>>k>>a>>b; long long int l=a+k-a%k; if(!(a%k))l-=k; int long long ks=10000000; ks=ks*ks; if(k<ks&&b>k*1458) b=k*1458; for(;l<=b;l+=k){ int q=0,l1=l;while(l1){q+=s[l1%10];l1/=10;} if(l==k*q){ h++; } } cout<<h<<endl; 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 | #include <iostream> using namespace std; int main() { long long int k,a,b; int h=0,i,s[10]; for(i=0;i<10;i++) s[i]=i*i; cin>>k>>a>>b; long long int l=a+k-a%k; if(!(a%k))l-=k; int long long ks=10000000; ks=ks*ks; if(k<ks&&b>k*1458) b=k*1458; for(;l<=b;l+=k){ int q=0,l1=l;while(l1){q+=s[l1%10];l1/=10;} if(l==k*q){ h++; } } cout<<h<<endl; return 0; } |