// Grzegorz Bukowiec // PA 2015 - Zadanie 0 #include <iostream> using namespace std; bool check(long long n, long long k) { long long sum = 0; long long m = n * k; while (m > 0) { sum += (m % 10) * (m % 10); m /= 10; } return n == sum; } int main() { ios_base::sync_with_stdio(0); long long k, a, b; cin >> k; cin >> a; cin >> b; a = (a + k - 1) / k; b /= k; b = (b > 1486 ? 1486 : b); int counter = 0; for (long long i = a; i <= b; ++i) { if (check(i, k)) { ++counter; } } cout << counter; 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 | // Grzegorz Bukowiec // PA 2015 - Zadanie 0 #include <iostream> using namespace std; bool check(long long n, long long k) { long long sum = 0; long long m = n * k; while (m > 0) { sum += (m % 10) * (m % 10); m /= 10; } return n == sum; } int main() { ios_base::sync_with_stdio(0); long long k, a, b; cin >> k; cin >> a; cin >> b; a = (a + k - 1) / k; b /= k; b = (b > 1486 ? 1486 : b); int counter = 0; for (long long i = a; i <= b; ++i) { if (check(i, k)) { ++counter; } } cout << counter; return 0; } |