コード例 #1
0
ファイル: PE03.py プロジェクト: annelagang/Project-Euler
def solve():
    n = 600851475143
    greatest = 0
    
    for prime in prime_gen():
        if(n < prime):
            break

        if(n % prime == 0):
            greatest = prime
            n = n / prime
        else:
            continue       

    print greatest
コード例 #2
0
ファイル: prob46.py プロジェクト: baopham/projectEuler
It was proposed by Christian Goldbach that every odd composite number can be written as the sum of a prime and twice a square.

9 = 7 + 2 x 1^2
15 = 7 + 2 x 2^2
21 = 3 + 2 x 3^2
25 = 7 + 2 x 3^2
27 = 19 + 2 x 2^2
33 = 31 + 2 x 1^2

It turns out that the conjecture was false.

What is the smallest odd composite that cannot be written as the sum of a prime and twice a square?
"""
from eulertools import prime_gen

primes = prime_gen(10000)
odd_comps = {o for o in range(1, 10001) if o % 2 != 0} - set(primes)

found = False
for odd_comp in odd_comps:
    for prime in primes:
        if prime >= odd_comp:
            break
        num = ((odd_comp - prime)/2) ** 0.5
        if int(num) != num:
            found = True
        else:
            found = False
            break
    if found:
        print odd_comp
コード例 #3
0
ファイル: prob41.py プロジェクト: baopham/projectEuler
"""
The number can't have 5 digits because it will be divisible by 3 ( 1+2+3+4+5 = 15)
Similarly, 8 digits and 9 digits wouldn't work as well.
And the minimum digits is 4 from the example. Thus we are looking for a prime of 7 digits
"""
from eulertools import prime_gen

primes = prime_gen(7654321)

for i in range(len(primes) - 1, 0, -1):
    p = primes[i]
    s = str(p)
    if len(s) == len(set(s)):
        if set(s) == set(str(i) for i in range(1, len(s) + 1)):
            print p
            break