貌似应该是找出n后,带回去看看是不是对的。
1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 #include<cmath> 5 #include<iostream> 6 7 #define ll long long 8 using namespace std; 9 typedef long long LL; 10 const int MAXN=9*9*18; 11 ll k,a,b; 12 13 ll solve(ll u) 14 { 15 ll n,sum,ret=0; 16 for(ll i=1;i<=MAXN;i++) 17 { 18 n=i*k;if(n>u) break; 19 sum=0; 20 while(n) 21 { 22 sum+=(n%10)*(n%10); 23 n/=10; 24 } 25 if(sum==i)ret++; 26 } 27 return ret; 28 } 29 int main() 30 { 31 scanf("%lld%lld%lld",&k,&a,&b); 32 printf("%lld ", solve(b)-solve(a-1)); 33 }