#include<iostream> using namespace std; int main() { long long k,a,b,s,i=0,w=0; double p; cin>>k>>a>>b; s=b; while(s!=0) { i++; s/=10; } p=double(i)*81*double(k); if(p<b) { b=p; } i=a/k; if(i*k!=a) { i=k*(i+1); } else { i=a; } while(i<=b) { s=0; a=i; while(a!=0) { s+=(a%10)*(a%10); a/=10; } if(double(s)*k==i) { w++; } i+=k; } cout<<w; }
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 | #include<iostream> using namespace std; int main() { long long k,a,b,s,i=0,w=0; double p; cin>>k>>a>>b; s=b; while(s!=0) { i++; s/=10; } p=double(i)*81*double(k); if(p<b) { b=p; } i=a/k; if(i*k!=a) { i=k*(i+1); } else { i=a; } while(i<=b) { s=0; a=i; while(a!=0) { s+=(a%10)*(a%10); a/=10; } if(double(s)*k==i) { w++; } i+=k; } cout<<w; } |