Initial commit
This commit is contained in:
37
problem-27.py
Normal file
37
problem-27.py
Normal file
@@ -0,0 +1,37 @@
|
||||
import math
|
||||
import itertools
|
||||
|
||||
|
||||
def is_prime(n):
|
||||
if n % 2 == 0 and n > 2 or n < 0:
|
||||
return False
|
||||
return all(n % i for i in range(3, int(math.sqrt(n)) + 1, 2))
|
||||
|
||||
|
||||
def form(n, a, b):
|
||||
result = n**2 + a*n + b
|
||||
return n**2 + a*n + b
|
||||
|
||||
|
||||
def get_sequence(pair):
|
||||
i = 0
|
||||
while True:
|
||||
if not is_prime(form(i, pair[0], pair[1])):
|
||||
return list(range(i))
|
||||
i += 1
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
a = list(range(-1000, 1000))
|
||||
b = list(range(-1000, 1001))
|
||||
pairs = list(itertools.product(a, b))
|
||||
print('number of pairs:', len(pairs))
|
||||
|
||||
longest = [pairs[0], [0]]
|
||||
for pair in pairs:
|
||||
seq = get_sequence(pair)
|
||||
if len(seq) > len(longest[1]):
|
||||
longest = (pair, seq)
|
||||
print(longest)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user