def isHarshadPrevPrime(splitNum): total = sum(splitNum) if total == 0: return True num = getNum(splitNum) if (num % total == 0): if (EulerSupport.miller_rabin(int(num / total))): return True return False
def isPrimeHarshad(num): s_num = str(num) list_of_ints = [int(i) for i in s_num] total = sum(list_of_ints) if total == 0: return True if (num % total == 0): if EulerSupport.miller_rabin(int(num / total)): #print("Test: " + str(num)) return recursiveHarshad(list_of_ints[:-1]) return False
def findSumFast(n): print ("Fast Way For N: %d"%n) print ("Start: " + time.strftime("%Y/%m/%d %H:%M:%S", time.localtime())) total = 0 num = [0]*20 # We default to 100 because 0-99 are not valid answers num[-3] = 1 #So we don't have to constantly compute length TOP = len(num)-1 i = TOP - 2 #while num[0] < 10: #Constantly Converting the Array to an int is a 100% time increase. #Could write code find the max array value and compares more constantly #Or if you use powers of 10 exclusively like below #while num[-15] < 10: while getNum(num) < n: #Clean Up step if we exceed the bounds of where we are set to 0 and go back up a spot if num[i] > 9: num[i] = 0 i -=1 num[i]+=1 #If our 1-Right deliminated value a Harshad and Reduces to a prime #Then go to the next highest value and check if prime #Else no good and increment elif i == TOP - 1: if isHarshadPrevPrime(num[:i+1]): i+=1 else: num[i] += 1 #If we are at the top check to see if our total number is a prime, else increment elif i == TOP: if (EulerSupport.miller_rabin(getNum(num))): val = getNum(num) total += val num[TOP]+=1 else: num[i]+=1 #Every number preceding the TOP must be a Harshad, except 2nd to top thats Harshad Prime elif i < TOP - 1: if isHarshad(num[:i+1]): i += 1 else: num[i]+=1 print ("Total %d"%total) print ("End: " + time.strftime("%Y/%m/%d %H:%M:%S", time.localtime())+ "\n") return total
def BruteForceSum(n): print ("Brute Force For N: %d"%n) print ("Start: " + time.strftime("%Y/%m/%d %H:%M:%S", time.localtime())) if n % 10 != 0: print("Must end in a 0") return(0) n = int(n / 10) total = 0 for x in range(1,n,1): if (isPrimeHarshad(x)): #print(x) for c in "1234567890": val = int(str(x)+c) if (EulerSupport.miller_rabin(val)): #if (True): total+=val #print(val) print ("Total %d"%total) print ("End: " + time.strftime("%Y/%m/%d %H:%M:%S", time.localtime())+"\n") return total
import sys import time sys.path.append("../SupportFunctions/") import EulerSupport print (time.strftime("%Y/%m/%d %H:%M:%S", time.localtime())) result = EulerSupport.getPrimes(103) print(len(result)) print(result[-3:]) print (time.strftime("%Y/%m/%d %H:%M:%S", time.localtime())) result = EulerSupport.getPrimes(1000) print(len(result)) print(result[-3:]) print (time.strftime("%Y/%m/%d %H:%M:%S", time.localtime())) print(EulerSupport.isPrime(17)) print(EulerSupport.miller_rabin(19)) print (time.strftime("%Y/%m/%d %H:%M:%S", time.localtime())) print (1066340417491710595814572169) print(EulerSupport.miller_rabin( 10663404174917)) print (time.strftime("%Y/%m/%d %H:%M:%S", time.localtime())) print(EulerSupport.miller_rabin( 1066340417491710595814572171)) print (time.strftime("%Y/%m/%d %H:%M:%S", time.localtime())) print(EulerSupport.miller_rabin( 19134702400093278081449423917)) print (time.strftime("%Y/%m/%d %H:%M:%S", time.localtime()))
import sys import time sys.path.append("../SupportFunctions/") import EulerSupport print(time.strftime("%Y/%m/%d %H:%M:%S", time.localtime())) result = EulerSupport.getPrimes(103) print(len(result)) print(result[-3:]) print(time.strftime("%Y/%m/%d %H:%M:%S", time.localtime())) result = EulerSupport.getPrimes(1000) print(len(result)) print(result[-3:]) print(time.strftime("%Y/%m/%d %H:%M:%S", time.localtime())) print(EulerSupport.isPrime(17)) print(EulerSupport.miller_rabin(19)) print(time.strftime("%Y/%m/%d %H:%M:%S", time.localtime())) print(1066340417491710595814572169) print(EulerSupport.miller_rabin(10663404174917)) print(time.strftime("%Y/%m/%d %H:%M:%S", time.localtime())) print(EulerSupport.miller_rabin(1066340417491710595814572171)) print(time.strftime("%Y/%m/%d %H:%M:%S", time.localtime())) print(EulerSupport.miller_rabin(19134702400093278081449423917)) print(time.strftime("%Y/%m/%d %H:%M:%S", time.localtime()))