#include <cstdio>
#include <cstring>
typedef unsigned long long ULL;
ULL a, b, k;
#define MAX_FN 1700
char buf[50];
ULL f(ULL n) {
ULL res = 0;
sprintf(buf, "%llu", n);
int l = strlen(buf);
//printf("buf: |%s|, len = %d\n",buf,l);
for(int i = 0; i < l; ++i) {
int v = (buf[i]-'0');
v *= v;
res += v;
}
return res;
}
int main() {
scanf("%llu %llu %llu", &k, &a, &b);
ULL now = k;
int count = 0;
while( now <= b && now < k * MAX_FN) {
if( now >= a && k * f(now) == now ) {
count++;
//printf("res: %llu\n\r", now);
}
now += k;
}
printf("%d\n",count);
}
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 | #include <cstdio> #include <cstring> typedef unsigned long long ULL; ULL a, b, k; #define MAX_FN 1700 char buf[50]; ULL f(ULL n) { ULL res = 0; sprintf(buf, "%llu", n); int l = strlen(buf); //printf("buf: |%s|, len = %d\n",buf,l); for(int i = 0; i < l; ++i) { int v = (buf[i]-'0'); v *= v; res += v; } return res; } int main() { scanf("%llu %llu %llu", &k, &a, &b); ULL now = k; int count = 0; while( now <= b && now < k * MAX_FN) { if( now >= a && k * f(now) == now ) { count++; //printf("res: %llu\n\r", now); } now += k; } printf("%d\n",count); } |
English