#include <stdio.h> #include <strings.h> #include <iostream> #include <string> #include <vector> using namespace std; typedef unsigned long long ullong; bool is(ullong v) { ullong x = v; do { ullong digit = x % 10; if (v%digit!=0) return false; x = x / 10; } while (x>1); return true; } int main() { ullong l, r; cin>>l>>r; ullong count = 0; vector<ullong> nums = {0}; for(int len=0; len<=18; ++len) { vector<ullong> new_nums; for (ullong v: nums) { for (int d=1; d<=9; ++d) { ullong totest = v*10+d; if (is(totest)) { //cout<<totest<<endl; new_nums.push_back(totest); if (totest>=l && totest<=r) count++; } } } nums.clear(); nums.insert(nums.end(), new_nums.begin(), new_nums.end()); new_nums.clear(); } cout<<count<<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 44 45 46 47 48 49 50 51 52 | #include <stdio.h> #include <strings.h> #include <iostream> #include <string> #include <vector> using namespace std; typedef unsigned long long ullong; bool is(ullong v) { ullong x = v; do { ullong digit = x % 10; if (v%digit!=0) return false; x = x / 10; } while (x>1); return true; } int main() { ullong l, r; cin>>l>>r; ullong count = 0; vector<ullong> nums = {0}; for(int len=0; len<=18; ++len) { vector<ullong> new_nums; for (ullong v: nums) { for (int d=1; d<=9; ++d) { ullong totest = v*10+d; if (is(totest)) { //cout<<totest<<endl; new_nums.push_back(totest); if (totest>=l && totest<=r) count++; } } } nums.clear(); nums.insert(nums.end(), new_nums.begin(), new_nums.end()); new_nums.clear(); } cout<<count<<endl; } |