#include <bits/stdc++.h> using namespace std; bool check(int64_t num) { int64_t temp = num; while(temp) { int dig = temp % 10; temp /= 10; if(dig == 0) return false; if(num % dig) return false; } return true; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int64_t l, r; cin >> l >> r; int sum = 0; for(int64_t i = l; i <= r; i++) { if(check(i)) { //cerr << i << "\n"; sum++; } } cout << sum; 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 | #include <bits/stdc++.h> using namespace std; bool check(int64_t num) { int64_t temp = num; while(temp) { int dig = temp % 10; temp /= 10; if(dig == 0) return false; if(num % dig) return false; } return true; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int64_t l, r; cin >> l >> r; int sum = 0; for(int64_t i = l; i <= r; i++) { if(check(i)) { //cerr << i << "\n"; sum++; } } cout << sum; return 0; } |