def prepareCoprimeMap(lim): for i in primeMap.keys(): if i > lim: return coprimeMap curCoprimeMap = {} for j in range(1, lim//i + 1): k = i * j curCoprimeMap[k] = False coprimeMap[i] = curCoprimeMap return coprimeMap
def slicePrimesToX(x): floor10 = (x // 10) + 1 minIndex = 4 * floor10 print('min index is ', minIndex) pm = list(primeMap.items()) primes = list(primeMap.keys()) n = 1 while True: if n > x: return dict(pm[:minIndex]) n = primes[minIndex] print('n is now ', n) minIndex-=1
def getRP3(n): if o1isPrime(n): return n-1 primes = primeMap.keys() tcoprimes = {} for pr in primes: isNotCoprime = n % pr == 0 if pr > n: return n - len(tcoprimes.keys()) if isNotCoprime: if pr != n: tcoprimes[pr] = False sliced = sliceToX2(pr,n) tcoprimes = {**tcoprimes, **sliced}
def prepareCoprimeMapNoEvens(lim): for i in primeMap.keys(): if i > lim: return coprimeMap curCoprimeMap = {} if i == 2: for j in range(1, lim//i + 1): k = i * j curCoprimeMap[k] = False else: for j in range(1, ((lim//i) // 2) + 2): k = i * ((j * 2) -1) if k > lim: continue curCoprimeMap[k] = False coprimeMap[i] = curCoprimeMap return coprimeMap
def getRP(n): seive = {} primes = primeMap.keys() if n in primes: return list(range(1, n)) while True: for pr in primes: if pr >= n: return processSeive(seive) nonfactor = n%pr != 0 # nonfactor true means it is coprime seive[pr] = nonfactor for i in range(2, n//pr + 1): j = i * pr if j < n: try: se = seive[j] if not se or nonfactor: continue seive[j] = nonfactor except: seive[j] = nonfactor return processSeive(seive)
from utils.annotations import track_performance from utils.mathHelpers import getFactors, isPrime from filterArrayAndOutput import primeMap factorsMap = {} primeList = list(primeMap.keys()) def getFactorsWithout1(n): try: f = factorsMap[n] return f except: factors = getFactors(n) factors.pop(0) factorsMap[n] = factors return factors def hasCommon(a, b): for i in a: if i in b: return True return False def getRelativePrimes(n): if isPrime(n): rps = list(range(n)) rps.pop(0) return rps
from utils.annotations import track_performance from filterArrayAndOutput import primeMap import binascii keys = list(map(lambda x: int(x), primeMap.keys())) memo = {} # { 122: False } def checkMemo(num): value = memo.get(num, None) if value is not None: return value memo[num] = checkPrime(num) return memo[num] def checkPrime(num): value = primeMap.get(num, None) if value is not None: return True return False # return num in keys # is this O(1)? - no - keys is an array def checkConcatenations(inputs): candidates = [] for a in range(len(inputs) - 1): for b in range(a + 1, len(inputs)): cands = assembleCandidate(inputs[a], inputs[b]) for cd in cands: candidates.append(cd)