#include <iostream> #include <algorithm> #include <set> using namespace std; int main() { unsigned long long result; unsigned long long R, L, tmp, i; int digit; bool isZero, isProper; set<int> digits; set<int>::iterator it; cin >> L; cin >> R; result = 0; for(i = L; i <= R; i++) { digits.clear(); tmp = i; isZero = false; isProper = true; while(tmp!=0) { digit = tmp % 10; tmp = tmp / 10; if(digit == 0) { isZero = true; break; } digits.insert(digit); } if(!isZero) { it = digits.begin(); while (it != digits.end()) { if(i % (*it) != 0) { isProper = false; break; } it++; } if(isProper) { result++; } } } cout << result; }
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 <algorithm> #include <set> using namespace std; int main() { unsigned long long result; unsigned long long R, L, tmp, i; int digit; bool isZero, isProper; set<int> digits; set<int>::iterator it; cin >> L; cin >> R; result = 0; for(i = L; i <= R; i++) { digits.clear(); tmp = i; isZero = false; isProper = true; while(tmp!=0) { digit = tmp % 10; tmp = tmp / 10; if(digit == 0) { isZero = true; break; } digits.insert(digit); } if(!isZero) { it = digits.begin(); while (it != digits.end()) { if(i % (*it) != 0) { isProper = false; break; } it++; } if(isProper) { result++; } } } cout << result; } |