#include <iostream> #include <cmath> using namespace std; bool CzySpelniaRownanie(long long int k, long long int n) { //cout << n << endl; long long int sum = 0; long long int p = n; while(p > 0) { //cout << p << " " << p % 10 << " " << (p % 10)*(p % 10) << " " << sum << endl; sum = sum + (p % 10)*(p % 10); p = (p / 10); } //cout << sum << endl; if (sum * k == n) return true; else return false; } int main() { ios_base::sync_with_stdio(0); long long int k, a, b, n, ile = 0; cin >> k >> a >> b; if (a % k == 0) n = a; else n = k * ((a / k) + 1); //pierwsza wielokrotnosc k w przedziale while (n <= b) { if (CzySpelniaRownanie(k, n)) { ile++; //cout << "### " << n << endl; } n += k; } 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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | #include <iostream> #include <cmath> using namespace std; bool CzySpelniaRownanie(long long int k, long long int n) { //cout << n << endl; long long int sum = 0; long long int p = n; while(p > 0) { //cout << p << " " << p % 10 << " " << (p % 10)*(p % 10) << " " << sum << endl; sum = sum + (p % 10)*(p % 10); p = (p / 10); } //cout << sum << endl; if (sum * k == n) return true; else return false; } int main() { ios_base::sync_with_stdio(0); long long int k, a, b, n, ile = 0; cin >> k >> a >> b; if (a % k == 0) n = a; else n = k * ((a / k) + 1); //pierwsza wielokrotnosc k w przedziale while (n <= b) { if (CzySpelniaRownanie(k, n)) { ile++; //cout << "### " << n << endl; } n += k; } cout << ile; return 0; } |