Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions project_euler/Problem_27/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

42 changes: 42 additions & 0 deletions project_euler/Problem_27/sol1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""
Euler discovered the remarkable quadratic formula:
n2 + n + 41
It turns out that the formula will produce 40 primes for the consecutive values n = 0 to 39. However, when n = 40, 402 + 40 + 41 = 40(40 + 1) + 41 is divisible by 41, and certainly when n = 41, 412 + 41 + 41 is clearly divisible by 41.
The incredible formula n2 − 79n + 1601 was discovered, which produces 80 primes for the consecutive values n = 0 to 79. The product of the coefficients, −79 and 1601, is −126479.
Considering quadratics of the form:
n² + an + b, where |a| < 1000 and |b| < 1000
where |n| is the modulus/absolute value of ne.g. |11| = 11 and |−4| = 4
Find the product of the coefficients, a and b, for the quadratic expression that produces the maximum number of primes for consecutive values of n, starting with n = 0.
"""
def isPrime(input):
if (input == 2):
return True
if (input <= 1):
return False
if (input % 2 == 0):
return False
for (int i = input - 2; i >= math.sqrt(input); i -= 2):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is C code, not Python.

if (input % i == 0):
return False
return True

def findMaxN(a,b):
max = 0
n = 2
while (isPrime(n*n + a*n + b)==True):
if (n > max):
max = n++
Copy link
Member

@cclauss cclauss Oct 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GitHub is painting this line in red because it contains a Python syntax error. Same thing a few line further down.

Please add doctests in each as discussed in CONTRIBUTING.md.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return max


def findMaxN(a,b):
max = 0
n = 2
while (isPrime(n*n + a*n + b)==True):
if (n > max):
max = n++
return max

if __name__ == "__main__":
print(solution(int(input().strip())))