From 1161f9a034de06a63538e3a9a0b7717098c744d9 Mon Sep 17 00:00:00 2001 From: Joshua Drake Date: Fri, 7 Apr 2023 08:13:49 -0500 Subject: Initial Commit --- Problem46.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Problem46.py (limited to 'Problem46.py') diff --git a/Problem46.py b/Problem46.py new file mode 100644 index 0000000..ecdba11 --- /dev/null +++ b/Problem46.py @@ -0,0 +1,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 \ No newline at end of file -- cgit v1.2.3