#include <iostream> using namespace std; int najmniejsza(unsigned long long x, unsigned long long y) { unsigned long long od = x; unsigned long long k = y; unsigned long long c = k; bool ta = false; while(x != true) { if(k >= od) return k; k += c; } } int policz(unsigned long long liczba, unsigned long long ka) { unsigned long long spr = liczba; unsigned long long test = 1; unsigned long long licznik = 0; while(test != 0) { if(spr % test == spr) { test = 0; } else { test *= 10; licznik++; } } unsigned long long dzielenie = liczba; unsigned long long i = 0; unsigned long long suma = 0; while(i != licznik) { suma += (dzielenie % 10)*(dzielenie % 10); dzielenie /= 10; i++; } unsigned long long wsp = ka; unsigned long long spr_dwa = liczba; if(suma * wsp == spr_dwa) { return 1; } else { return 0; } } int main() { unsigned long long k; unsigned long long a; unsigned long long b; cin >> k; cin >> a; cin >> b; unsigned long long klon_k = najmniejsza(a,k); unsigned long long ostatecznie = 0; bool juz = false; while(juz != true) { if(policz(klon_k,k) == 1) ostatecznie++; klon_k += k; if(klon_k > b) juz = true; } cout << ostatecznie; 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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | #include <iostream> using namespace std; int najmniejsza(unsigned long long x, unsigned long long y) { unsigned long long od = x; unsigned long long k = y; unsigned long long c = k; bool ta = false; while(x != true) { if(k >= od) return k; k += c; } } int policz(unsigned long long liczba, unsigned long long ka) { unsigned long long spr = liczba; unsigned long long test = 1; unsigned long long licznik = 0; while(test != 0) { if(spr % test == spr) { test = 0; } else { test *= 10; licznik++; } } unsigned long long dzielenie = liczba; unsigned long long i = 0; unsigned long long suma = 0; while(i != licznik) { suma += (dzielenie % 10)*(dzielenie % 10); dzielenie /= 10; i++; } unsigned long long wsp = ka; unsigned long long spr_dwa = liczba; if(suma * wsp == spr_dwa) { return 1; } else { return 0; } } int main() { unsigned long long k; unsigned long long a; unsigned long long b; cin >> k; cin >> a; cin >> b; unsigned long long klon_k = najmniejsza(a,k); unsigned long long ostatecznie = 0; bool juz = false; while(juz != true) { if(policz(klon_k,k) == 1) ostatecznie++; klon_k += k; if(klon_k > b) juz = true; } cout << ostatecznie; return 0; } |