#include <iostream> #ifdef DEBUG #define DEBUG_LOG(x) do { \ std::cerr << x << std::endl;\ } while (0) #else #define DEBUG_LOG(x) do { \ } while (0) #endif bool isProper(uint64_t val) { std::string str = std::to_string(val); uint64_t divider; std::size_t found=str.find('0'); if (found!=std::string::npos) return false; found = str.find('2'); if ((val & 1) != 0 && found != std::string::npos) return false; found = str.find('5'); if (found != std::string::npos && str.c_str()[str.size()-1] != '5') return false; for (int i = 0; i < str.size(); i++) { char c = str.c_str()[i]; divider = c - '0'; if (val % divider != 0) return false; } return true; } void Run(std::istream& input, std::ostream& output) { uint64_t l, r; input >>l; input >>r; uint64_t cnt=0; for(uint64_t i = l; i <= r; ++i) { if (isProper(i)) ++cnt; } output << cnt << "\n"; } #ifndef DEBUG int main(int argc, char* argv[]) #else int main_(int argc, char* argv[]) #endif { ::Run(std::cin, std::cout); 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 49 50 51 52 53 54 55 56 57 58 59 60 61 | #include <iostream> #ifdef DEBUG #define DEBUG_LOG(x) do { \ std::cerr << x << std::endl;\ } while (0) #else #define DEBUG_LOG(x) do { \ } while (0) #endif bool isProper(uint64_t val) { std::string str = std::to_string(val); uint64_t divider; std::size_t found=str.find('0'); if (found!=std::string::npos) return false; found = str.find('2'); if ((val & 1) != 0 && found != std::string::npos) return false; found = str.find('5'); if (found != std::string::npos && str.c_str()[str.size()-1] != '5') return false; for (int i = 0; i < str.size(); i++) { char c = str.c_str()[i]; divider = c - '0'; if (val % divider != 0) return false; } return true; } void Run(std::istream& input, std::ostream& output) { uint64_t l, r; input >>l; input >>r; uint64_t cnt=0; for(uint64_t i = l; i <= r; ++i) { if (isProper(i)) ++cnt; } output << cnt << "\n"; } #ifndef DEBUG int main(int argc, char* argv[]) #else int main_(int argc, char* argv[]) #endif { ::Run(std::cin, std::cout); return 0; } |