Blue Bridge Cup Python Group - Arithmetic Prime Sequence

Blue Bridge Cup Python Group - Arithmetic Prime Sequence

Topic description

This question is a fill-in-the-blank question. After calculating the result, use the output statement in the code to output the filled result.
2,3,5,7,11,13,… is a sequence of prime numbers. Similar: 7, 37, 67, 97, 127, 157 The arithmetic sequence composed entirely of prime numbers is called the arithmetic prime sequence.

The above sequence has a tolerance of 30 and a length of 6.

In 2004, Green and Chinese Tao Zhexuan cooperated to prove that there is an arithmetic sequence of prime numbers of any length. This is an amazing achievement in the field of number theory!

Based on this theory, please use the computer in your hand to search with confidence:
What is the minimum tolerance of the arithmetic prime sequence of length 10?

Running limit
Maximum running time: 1s
Maximum running memory: 128M

def f(n):
    k = int(n ** 0.5)
    for i in range(2,k+1):
        if n % i == 0:
            return False
    else:
        return True
        
num = []
for i in range(3,1000,2):
    for j in range(1,1000):
        if f(i+j) and f(i+2*j) and f(i+3*j) and f(i+4*j) and f(i+5*j) and f(i+6*j) and f(i+7*j) and f(i+8*j) and f(i+9*j) and f(i):
            num.append(j)

print(min(num))

Thank you for your support. Your one-click three-connection is the biggest driving force for Ganggang students!

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324320767&siteId=291194637