#include <iostream> #include <string> using namespace std; int potNum(int l, int r) { int sum = 0; for (int num = l; num <= r; num++) { string str_num = to_string(num); sum++; for (char dig : str_num) { if (dig == '0' || num % (dig - '0') != 0) { sum--; break; } } } return sum; } int main() { string input; getline(cin, input); size_t pos = input.find(' '); int n1 = stoi(input.substr(0, pos)); int n2 = stoi(input.substr(pos + 1)); cout << potNum(n1, n2); }
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 | #include <iostream> #include <string> using namespace std; int potNum(int l, int r) { int sum = 0; for (int num = l; num <= r; num++) { string str_num = to_string(num); sum++; for (char dig : str_num) { if (dig == '0' || num % (dig - '0') != 0) { sum--; break; } } } return sum; } int main() { string input; getline(cin, input); size_t pos = input.find(' '); int n1 = stoi(input.substr(0, pos)); int n2 = stoi(input.substr(pos + 1)); cout << potNum(n1, n2); } |