You can cut down the possibilities you have to check

来源: AnaZhang 2011-12-31 13:20:06 [] [博客] [旧帖] [给我悄悄话] 本文已被阅读: 0 次 (808 bytes)
回答: 有没有好办法?cma2011-12-31 10:22:52

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.

所有跟帖: 

谢谢。但标准答案与你的不一样。 -cma- 给 cma 发送悄悄话 (37 bytes) () 12/31/2011 postreply 17:22:45

Oops, 215 -AnaZhang- 给 AnaZhang 发送悄悄话 AnaZhang 的博客首页 (0 bytes) () 12/31/2011 postreply 17:37:58

请您先登陆,再发跟帖!

发现Adblock插件

如要继续浏览
请支持本站 请务必在本站关闭/移除任何Adblock

关闭Adblock后 请点击

请参考如何关闭Adblock/Adblock plus

安装Adblock plus用户请点击浏览器图标
选择“Disable on www.wenxuecity.com”

安装Adblock用户请点击图标
选择“don't run on pages on this domain”