#include <iostream> #include <string> using namespace std; bool checkZero(unsigned long long x) { string xStr = to_string(x); for (int i = 0; i < xStr.length(); i++) { if (xStr[i] == '0') return false; } return true; } void processNumber(unsigned long long x, int &counter){ if (!checkZero(x)) return; string xStr = to_string(x); for (int i = 0; i < xStr.length(); i++){ if (x%(int(xStr[i])-48) == 0) continue; return; } counter++; return; } int main() { unsigned long long l, r; cin >> l >> r; int counter = 0; for (l; l <= r; l++) { processNumber(l, counter); } cout << counter; 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 | #include <iostream> #include <string> using namespace std; bool checkZero(unsigned long long x) { string xStr = to_string(x); for (int i = 0; i < xStr.length(); i++) { if (xStr[i] == '0') return false; } return true; } void processNumber(unsigned long long x, int &counter){ if (!checkZero(x)) return; string xStr = to_string(x); for (int i = 0; i < xStr.length(); i++){ if (x%(int(xStr[i])-48) == 0) continue; return; } counter++; return; } int main() { unsigned long long l, r; cin >> l >> r; int counter = 0; for (l; l <= r; l++) { processNumber(l, counter); } cout << counter; return 0; } |