枚举。
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; long long k,a,b,ans=0; bool check(long long x,long long y) { if ((x<a) || (x>b)) return false; long long ret=0; while (x) { ret+=(x%10)*(x%10); x/=10; } if (ret!=y) return false; return true; } int main() { scanf("%lld%lld%lld",&k,&a,&b); for (long long i=0;i<=1458;i++) { if (i*k>b) break; if (check(i*k,i)) ans++; } printf("%lld\n",ans); return 0; }
时间: 2024-11-16 16:20:03