#include <iostream> #include <string> #include <bitset> using lli = long long int; std::bitset<10> numbers; bool check(lli i) { std::string str = std::to_string(i); if (str.back() == '0') return false; numbers.reset(); for (auto const& ch : str) numbers.set(ch - 48); if (numbers[0]) return false; for (int nr = 0; nr < numbers.size(); ++nr) { if (!numbers[nr]) continue; if (i % nr != 0) return false; } return true; } lli solve(lli l, lli r) { lli count = 0; for (lli i = l; i<=r; ++i) { if (check(i)) ++count; } return count; } int main() { lli l,r; std::cin >> l >> r; std::cout << solve(l,r) << std::endl; 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 | #include <iostream> #include <string> #include <bitset> using lli = long long int; std::bitset<10> numbers; bool check(lli i) { std::string str = std::to_string(i); if (str.back() == '0') return false; numbers.reset(); for (auto const& ch : str) numbers.set(ch - 48); if (numbers[0]) return false; for (int nr = 0; nr < numbers.size(); ++nr) { if (!numbers[nr]) continue; if (i % nr != 0) return false; } return true; } lli solve(lli l, lli r) { lli count = 0; for (lli i = l; i<=r; ++i) { if (check(i)) ++count; } return count; } int main() { lli l,r; std::cin >> l >> r; std::cout << solve(l,r) << std::endl; return 0; } |