#include <stdlib.h> #include <stdio.h> long long f(long long number) { long long result = 0; while (number > 0) { int digit = number % 10; number /= 10; result += digit * digit; } return result; } int main(int argc, char* argv[]) { if (argc < 4) return -1; int k, cnt = 0; long long int a; long long int b; long long int n; k = atoi(argv[1]); a = atoll(argv[2]); b = atoll(argv[3]); while (a < b) { n = a; if (k * f(n) == n) { cnt++; } a++; } printf("%d", cnt); 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 | #include <stdlib.h> #include <stdio.h> long long f(long long number) { long long result = 0; while (number > 0) { int digit = number % 10; number /= 10; result += digit * digit; } return result; } int main(int argc, char* argv[]) { if (argc < 4) return -1; int k, cnt = 0; long long int a; long long int b; long long int n; k = atoi(argv[1]); a = atoll(argv[2]); b = atoll(argv[3]); while (a < b) { n = a; if (k * f(n) == n) { cnt++; } a++; } printf("%d", cnt); return 0; } |