Example #1
0
def truncatable_primes(digits: Tuple[int] = ()) -> Iterable[int]:
    candidate_digits_count = len(digits) + 1
    for digit in possible_digits:
        candidate_digits = (digit,) + digits
        candidate_number = digits_to_number(candidate_digits)
        if not prime(candidate_number):
            continue

        if (candidate_digits_count > 1 and
                all(prime(digits_to_number(candidate_digits[:position]))
                    for position in range(1, candidate_digits_count))):
            yield candidate_number

        yield from truncatable_primes(candidate_digits)
Example #2
0
File: p27.py Project: kryptn/euler
def formula_test(a,b):
    n = 0
    while True:
        if prime(n**2 + a*n + b):
            n += 1
        else:
            break
    return n
Example #3
0
def consecutive_quadratic_primes_count(coefficients: Tuple[int, int]) -> int:
    linear_coefficient, constant_term = coefficients

    def quadratic_formula(n: int) -> int:
        return n**2 + linear_coefficient * n + constant_term

    for number in count(0):
        value = quadratic_formula(number)
        if value < 0 or not prime(value):
            return number
Example #4
0
def primeFactors(n):
    result = []
    
    while n > 1:
        i = 2
        while i <= n:
            if not n % i and prime(i):
                result.append(i)
                n //= i
                break
               
            i += 1
            
    return result
Example #5
0
    
def nConsecutif(n, m):
    result = 0
    while numberOfPrimeFactors(n) == m:
        n += 1
        result += 1
    
    return result

    
# ********************************************************************
startTime = time.time()
      
start = 7*11*13*17
n = start
value = 4
   
while True:
    if not prime(n):
        consecutif = nConsecutif(n, value)
        if consecutif >= value:
            break
            
        n += consecutif + 1
    else:
        n += 1
    
print(n)
print(time.time() - startTime)

Example #6
0
File: p35.py Project: kryptn/euler
def answer(limit):
    return [x for x in xrange(2,limit) if prime(x) and all([prime(int(y)) for y in rotations(str(x))])]
Example #7
0
# length of the square spiral for which the ratio of primes along both diagonals 
# first falls below 10%?

from utils import prime
from time import time
# ******************************************************************************
startTime = time()

length = 1
primeTotal = 0
total = 1
ratio = 1

while ratio >= 0.10:
    length += 2
    total += 4
    
    diagonal = length**2
    for n in range(3):
        diagonal -= length - 1
        if prime(diagonal):
            primeTotal += 1
    
    ratio = primeTotal / total
    # print(length, primeTotal, total, ratio)
            

print(length)
print(time() - startTime)
    
    
Example #8
0
# ********************************************************************
from utils import prime, sortedList
import time

startTime = time.time()

primeList = sortedList([])
primeList.add(2)

squareList = sortedList([])
squareList.addList([1,4])


start = 1 # en fait, 3
n = start
bool = True
while bool:
    n += 2
    squareList.add(n**2)
    squareList.add((n+1)**2)
    
    if prime(n):
        primeList.add(n)
    else:
        bool = conjecture(n)

    
print("Result :", n)
print(time.time() - startTime)