#include <iostream> #include <cstdlib> using namespace std; long long int inline rachuj(long long int x) { long long int suma = 0; while (x > 0) { int c = x % 10; suma += c*c; x /= 10; } return suma; } int main() { long long int k, a, b; long long int duzo = 1458LL; cin >> k >> a >> b; long long int ile = 0; for (long long int f = 0; f <= duzo; ++f) { long long n = k * f; if (a <= n && n <= b && rachuj(n) == f) ++ile; } cout << ile; 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 | #include <iostream> #include <cstdlib> using namespace std; long long int inline rachuj(long long int x) { long long int suma = 0; while (x > 0) { int c = x % 10; suma += c*c; x /= 10; } return suma; } int main() { long long int k, a, b; long long int duzo = 1458LL; cin >> k >> a >> b; long long int ile = 0; for (long long int f = 0; f <= duzo; ++f) { long long n = k * f; if (a <= n && n <= b && rachuj(n) == f) ++ile; } cout << ile; return 0; } |