#include<stdio.h> int main() { int a, b, i, k, n, ostD; //a = 5000; //b = 10000; //k = 51; if (scanf("%d", &k) == 1) {} if (scanf("%d", &a) == 1) {} if (scanf("%d", &b) == 1) {} i=a; int res = 0; while (i<=b) { n = i / k; ostD = i % k; if (ostD!=0) { i++; continue; } //printf("ostd %d\n", ostD); char i_s[30]; sprintf(i_s, "%d", i); int j = 0; int len = 0; int nn = i; while(nn!=0) { nn/=10; /* n=n/10 */ ++len; } int sum = 0; while (j < len) { int x = (int)i_s[j] - 48; sum += x*x; //printf("%d\n", x); j = j+1; } if (n==sum) { //printf("ok %d\n", i); res++; } i++; } printf("%d\n", res); 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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | #include<stdio.h> int main() { int a, b, i, k, n, ostD; //a = 5000; //b = 10000; //k = 51; if (scanf("%d", &k) == 1) {} if (scanf("%d", &a) == 1) {} if (scanf("%d", &b) == 1) {} i=a; int res = 0; while (i<=b) { n = i / k; ostD = i % k; if (ostD!=0) { i++; continue; } //printf("ostd %d\n", ostD); char i_s[30]; sprintf(i_s, "%d", i); int j = 0; int len = 0; int nn = i; while(nn!=0) { nn/=10; /* n=n/10 */ ++len; } int sum = 0; while (j < len) { int x = (int)i_s[j] - 48; sum += x*x; //printf("%d\n", x); j = j+1; } if (n==sum) { //printf("ok %d\n", i); res++; } i++; } printf("%d\n", res); return 0; } |