題目描述
對於一個正整數 n,定義
1≤k,a,b≤10^18
a≤b
樣例輸入
51 5000 10000
樣例輸出
3
題目分析
可以發現當每一位都取9的時候答案最大,那麼我們可以發現最大的平方和爲
代碼
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
const int MAXN = 9*9*18;
LL k, a, b;
LL solve(LL u){
LL n, sum, ret = 0;
for(LL i=1; i<=MAXN; i++){
n = i * k;
if(n > u) break;
sum = 0;
while(n){
sum += (n%10)*(n%10);
n /= 10;
}
if(sum == i)
ret ++;
}
return ret;
}
int main(){
scanf("%I64d%I64d%I64d", &k, &a, &b);
printf("%I64d\n", solve(b) - solve(a-1));
return 0;
}