#include <cstdio> #include <cmath> using std::pow; using std::scanf; using std::printf; int main() { const long long int maxNum = pow(10, 18); const int maxSum = (9*9) * 18; long long int a; long long int b; long long int k; scanf("%lld%lld%lld", &k, &a, &b); int correctNumbers = 0; for (int expectedSum = 1; expectedSum <= maxSum; expectedSum++) { if (maxNum / k < expectedSum) break; long long int suspectNum = expectedSum * k; if (suspectNum < a) continue; if (suspectNum > b) break; int suspectSum = 0; while (suspectNum) { int digit = suspectNum % 10; suspectSum += digit * digit; suspectNum /= 10; } if (suspectSum == expectedSum) correctNumbers++; } printf("%d\n", correctNumbers); 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 | #include <cstdio> #include <cmath> using std::pow; using std::scanf; using std::printf; int main() { const long long int maxNum = pow(10, 18); const int maxSum = (9*9) * 18; long long int a; long long int b; long long int k; scanf("%lld%lld%lld", &k, &a, &b); int correctNumbers = 0; for (int expectedSum = 1; expectedSum <= maxSum; expectedSum++) { if (maxNum / k < expectedSum) break; long long int suspectNum = expectedSum * k; if (suspectNum < a) continue; if (suspectNum > b) break; int suspectSum = 0; while (suspectNum) { int digit = suspectNum % 10; suspectSum += digit * digit; suspectNum /= 10; } if (suspectSum == expectedSum) correctNumbers++; } printf("%d\n", correctNumbers); return 0; } |