#include <cstdio> #include <cstdint> #include <cinttypes> #include <vector> #include <algorithm> #include <cmath> // const std::vector<uint64_t> primes { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97 }; int main(int argc, char const *argv[]) { uint64_t only_divisible_by_count; scanf("%" PRIu64, &only_divisible_by_count); uint64_t range_limit; scanf("%" PRIu64, &range_limit); std::vector<uint64_t> only_divisible_by; only_divisible_by.reserve(only_divisible_by_count); while (only_divisible_by_count--) { uint64_t tmp; scanf("%" PRIu64, &tmp); only_divisible_by.push_back(tmp); } // std::sort(only_divisible_by.begin(), only_divisible_by.end()); uint64_t proposed_max = range_limit; do { uint64_t foo = proposed_max; for (const auto &prime : only_divisible_by) { while (foo % prime == 0) { foo /= prime; } } if (foo == 1) { break; } } while (--proposed_max); printf("%" PRIu64 "\n", proposed_max); 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 | #include <cstdio> #include <cstdint> #include <cinttypes> #include <vector> #include <algorithm> #include <cmath> // const std::vector<uint64_t> primes { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97 }; int main(int argc, char const *argv[]) { uint64_t only_divisible_by_count; scanf("%" PRIu64, &only_divisible_by_count); uint64_t range_limit; scanf("%" PRIu64, &range_limit); std::vector<uint64_t> only_divisible_by; only_divisible_by.reserve(only_divisible_by_count); while (only_divisible_by_count--) { uint64_t tmp; scanf("%" PRIu64, &tmp); only_divisible_by.push_back(tmp); } // std::sort(only_divisible_by.begin(), only_divisible_by.end()); uint64_t proposed_max = range_limit; do { uint64_t foo = proposed_max; for (const auto &prime : only_divisible_by) { while (foo % prime == 0) { foo /= prime; } } if (foo == 1) { break; } } while (--proposed_max); printf("%" PRIu64 "\n", proposed_max); return 0; } |