#include <cstdio> #include <algorithm> using namespace std; int f(long long n) { int w=0; while(n) { int c=n%10; w += c*c; n/=10; } return w; } int main() { long long a,b,k; scanf("%lld%lld%lld",&k,&a,&b); int c=(a-1)/k+1; int d=min(b/k,18*81LL); int ans=0; for (int s=c;s<=d;s++) if (f(s*k)==s) ans++;//,printf("%lld\n",s*k); printf("%d",ans); 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 | #include <cstdio> #include <algorithm> using namespace std; int f(long long n) { int w=0; while(n) { int c=n%10; w += c*c; n/=10; } return w; } int main() { long long a,b,k; scanf("%lld%lld%lld",&k,&a,&b); int c=(a-1)/k+1; int d=min(b/k,18*81LL); int ans=0; for (int s=c;s<=d;s++) if (f(s*k)==s) ans++;//,printf("%lld\n",s*k); printf("%d",ans); return 0; } |