You can eliminate from consideration any number above 210 (42 * 5) because for any number above 210, you can add a multiple of 42 and a multiple of 5 to get that number. Then, you can remove any multiples of 2, 3, or 7 (the prime factors of 42) and any numbers ending in 7 above 42, ending in 9 above 84, ending in 1 above 126, or ending in 3 above 168 to remove the numbers that are a multiple of 42 plus a multiple of 5. You can repeat this process for other prime numbers, but now you have very few possibilities to test, so you can brute-force it. 205 is 84 + 121, 185 is 42 + 143, 175 is 84 + 91, and 163 is 42 + 121. !155! is the largest number that cannot satisfy the conditions. This isn't a really pretty solution, but most problems with prime numbers require brute force to some extent.
You can cut down the possibilities you have to check
所有跟帖:
•
谢谢。但标准答案与你的不一样。
-cma-
♂
(37 bytes)
()
12/31/2011 postreply
17:22:45
•
Oops, 215
-AnaZhang-
♀
(0 bytes)
()
12/31/2011 postreply
17:37:58