#include <iostream> #include <string> int potyczkow(int l, int r) { int sum=0; for (int i = l; i <= r; i++) { std::string tmp = std::to_string(i); bool ok = true; for (int j = 0; j < (int)tmp.length(); j++) { if (tmp[j] == '0' || i % (tmp[j] % 48) != 0) { ok = false; break; } } if (ok) { sum++; } } return sum; } int main() { int l=0, r=-1; while (std::cin.fail() || l<1 || r<1 || (r<l)) { std::cin.clear(); std::cout << "Wprowadz l: "; std::cin >> l; std::cout << "Wprowadz r: "; std::cin >> r; std::cout << std::endl; } std::cout << "Ilosc liczb Potyczkowa w przedziale ["<<l<<", "<<r<<"] wynosi " << potyczkow(l, r) << std::endl; }
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 | #include <iostream> #include <string> int potyczkow(int l, int r) { int sum=0; for (int i = l; i <= r; i++) { std::string tmp = std::to_string(i); bool ok = true; for (int j = 0; j < (int)tmp.length(); j++) { if (tmp[j] == '0' || i % (tmp[j] % 48) != 0) { ok = false; break; } } if (ok) { sum++; } } return sum; } int main() { int l=0, r=-1; while (std::cin.fail() || l<1 || r<1 || (r<l)) { std::cin.clear(); std::cout << "Wprowadz l: "; std::cin >> l; std::cout << "Wprowadz r: "; std::cin >> r; std::cout << std::endl; } std::cout << "Ilosc liczb Potyczkowa w przedziale ["<<l<<", "<<r<<"] wynosi " << potyczkow(l, r) << std::endl; } |