summaryrefslogtreecommitdiff
path: root/Problem46.py
blob: ecdba1156552c59f264a3e29db5ceeb98baf8266 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#Joshua Drake 9/9/2021
import math
def isPrime(n):
    for x in range(2,int(n/2)+1):
        if n%x == 0: return False
    return True
def nextprime(n):
    n+=1
    while isPrime(n) == False:
        n+=1
    return n
def isComposite(n):
    if isPrime(n) == False: return True
    else: return False
def nextOddComposite(n):
    newcomposite = n+1
    while isComposite(newcomposite) == False or newcomposite % 2 == 0:
        newcomposite+=1
    return newcomposite
composite,prime = 9,2
while(1):
    prime = 2
    while prime < composite:
        for square in range(1,int(math.sqrt(composite))+1):
            if prime + (2*pow(square,2)) == composite:
                composite = nextOddComposite(composite) 
                prime = 2
                break
        prime = nextprime(prime)
    print("Answer is:" , composite)
    break