鱼C论坛

 找回密码
 立即注册
查看: 2358|回复: 2

题目146:考察一个质数模式

[复制链接]
发表于 2016-8-31 16:12:49 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
Investigating a Prime Pattern

The smallest positive integer n for which the numbers n2+1, n2+3, n2+7, n2+9, n2+13, and n2+27 are consecutive primes is 10. The sum of all such integers n below one-million is 1242490.

What is the sum of all such integers n below 150 million?


题目:

使得 n2+1, n2+3, n2+7, n2+9, n2+13, 以及 n2+27 为连续质数的最小的正整数 n 为 10。100 万以下所有满足上述条件的 n 值之和是 1242490。

求 1 亿五千万以下所有满足上述条件的 n 值之和。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2017-8-16 08:58:56 | 显示全部楼层
很没有效率的暴力解法
def is_prime(n):
        if n<2: return False
        for p in (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):
                if pow(p,n-1,n) != 1:
                        return False
        return True

def solve(limit):
        n = 0
        for i in range(1,limit//10):
                t1 = 10*i
                t2 = 10*i+2
                t3 = 10*i+8
                if is_prime(t3*t3+1) and is_prime(t3*t3+3) and is_prime(t3*t3+7) and is_prime(t3*t3+9) and is_prime(t3*t3+13) and is_prime(t3*t3+27) and not is_prime(t3*t3+19) and not is_prime(t3*t3+21):
                        n += t3
                        continue
                if is_prime(t2*t2+1) and is_prime(t2*t2+3) and is_prime(t2*t2+7) and is_prime(t2*t2+9) and is_prime(t2*t2+13) and is_prime(t2*t2+27) and not is_prime(t2*t2+19) and not is_prime(t2*t2+21):
                        n += t2
                        continue
                if is_prime(t1*t1+1) and is_prime(t1*t1+3) and is_prime(t1*t1+7) and is_prime(t1*t1+9) and is_prime(t1*t1+13) and is_prime(t1*t1+27) and not is_prime(t1*t1+19) and not is_prime(t1*t1+21):
                        n += t1
                        continue
        return n
print(solve(150000000))
676333270
[Finished in 993.5s]
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-4-20 15:06:36 | 显示全部楼层
根据n^2 + 1是素数所以n一定是偶数,所以:n = 0 mod 2.
由于n^2 + 3 是素数所以:n = 1,2 mod 3.
如果n=1 mod 5,则n^2 + 1是一个偶数,不行!
如果n=2 mod 5 则n^1+1是5的倍数,不行!
如果n=3 mod 5 则n^2+1是10的倍数,不行!
如果n=4 mod 5 则n^2 + 9是5的倍数,不行!
所以n=0 mod 5 故n一定是10的倍数。
如果n=0 mod 7 则n^2 + 7是7的倍数,不行!
如果n=1 mod 7 则n^2 + 13是7的倍数,不行!
如果n=2 mod 7 则n^2 + 3是7的倍数,不行!
如果n=5 mod 7 则n^2 + 3是7的倍数,不行!
如果n=6 mod 7 则n^2 + 13是7的倍数,不行!
所以n除7余数只能是3或4。

答案:676333270
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-7-2 21:33

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表