def truncatableR2L(p): coefficient = 10 q = p while q > 10: q = p / coefficient if not prime.isPrime(q): return False coefficient *= 10 return True
def diag(): isPrime(10**9) # Sieve init last = 1 diagNumsCount = 1 primeCountTillNow = 0 for layer in count(1): sideLength = 2 * layer for side in range(1, 5): last += sideLength if isPrime(last): primeCountTillNow += 1 diagNumsCount += 1 ratio = primeCountTillNow / diagNumsCount if layer % 100 == 0: print("layer: ", layer, ", ratio: ", ratio, ", last: ", last, ", primes: ", primeCountTillNow, ", tot: ", diagNumsCount) if ratio < 0.1: return sideLength
def truncatableL2R(p): coefficient = 10 m = 0 while m < p: m = p % coefficient if not prime.isPrime(m): return False coefficient *= 10 return True
def main(): ps = primes(10**6) biggest = 1 for start in range(len(ps)): acc = 0 nbTerms = 0 if len(ps[start:]) < biggest: continue for p in ps[start:]: nbTerms += 1 acc += p if acc > 10**6: continue if isPrime(acc) and nbTerms > biggest: biggest = nbTerms print("prime ", acc, " with ", nbTerms, " terms")
def isCircularPrimes(n): if n < 20: return True q = n p = 10 w = 1 while True: if q / p != 0: w += 1 else: break p *= 10 p = 10**(w - 1) while w > 1: w -= 1 n = (n % p) * 10 + n / p if not prime.isPrime(n): return False return True
def test(p): digits = countItems(str(p)) dupDigits = dict(filter(lambda x: x[1] > 1, digits.items())) for digit in dupDigits.keys(): serie = 0 smallest = 0 for i in range(10): pStr = str(p) if i == 0 and pStr[0] == digit: continue num = int(pStr.replace(digit, str(i))) if (isPrime(num)): print(num) serie += 1 if smallest == 0: smallest = num print(serie) if serie == 8: print(smallest) return True return False
import sys from utils import prime try: whichPrime = int(sys.argv[1]) except: sys.exit("Script execution must follow the following format: python problem7.py <whichPrime>") count = 0 position = 1 while count != whichPrime: if prime.isPrime(position): count += 1 position += 1 sys.exit(str(position - 1))
import sys from utils import prime try: startRange = int(sys.argv[1]) endRange = int(sys.argv[2]) except: sys.exit("Script execution must follow the following format: python problem10.py <startRange> <endRange>") sum = 0 for x in range(startRange, endRange + 1): if prime.isPrime(x): sum += x sys.exit(str(sum))
def isASquare(n): for i in range(1, n / 2): if n == i ** 2: return True if i ** 2 > n: break return False def isTwiceASquare(n): if n == 0: return True if n == 1 : return False if n % 2 != 0: return False q = n / 2 return isASquare(q) if __name__ == '__main__': n = 35 while True: for i in range(n, 0, -1): if prime.isPrime(i) and isTwiceASquare(n - i): break if i == 1: print('{} {} {}'.format(n, i, n - i)) exit() n += 2