#include <iostream> #include <cmath> using std::cout; using std::cin; inline long int oblicz_kwadraty_cyfr_dla_n(long long int n) { unsigned int suma = 0; while(n > 0) { suma += pow(n % 10, 2); n /= 10; } return suma; } int main() { long long int k, a, b, n; unsigned int wynik = 0; cin >> k >> a >> b; while(a < b) { if(k * oblicz_kwadraty_cyfr_dla_n(a) == a) wynik += 1; ++a; } cout << wynik; 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 | #include <iostream> #include <cmath> using std::cout; using std::cin; inline long int oblicz_kwadraty_cyfr_dla_n(long long int n) { unsigned int suma = 0; while(n > 0) { suma += pow(n % 10, 2); n /= 10; } return suma; } int main() { long long int k, a, b, n; unsigned int wynik = 0; cin >> k >> a >> b; while(a < b) { if(k * oblicz_kwadraty_cyfr_dla_n(a) == a) wynik += 1; ++a; } cout << wynik; return 0; } |