コード例 #1
0
import time
from primes import get_primes, divisors, m_r
START = time.time()
SIZE = 10**6 * 5
LIM = 10**5
primes = get_primes(SIZE)

div308 = divisors(308)
results = []

for p in primes:
    if len(results) > LIM: break
    if not any([m_r(div * p + 1) for div in div308]):
        results.append(p)

print results[LIM - 2] * 308, len(results)

for repetition in xrange(10):

    resultSet = set(results)
    for index, a in enumerate(results):
        if a * results[0] > results[LIM]: break

        for bIndex in xrange(index + 1):
            b = results[bIndex]
            p = a * b

            if a * b > results[LIM]: break
            if not any([m_r(div * p + 1) for div in div308]):
                if len(filter(lambda x: x not in resultSet,
                              divisors(p)[1:-1])) == 0:
コード例 #2
0
ファイル: prob241.py プロジェクト: mercurium/proj_euler
import time
from primes import divisors, factor, pfactor_gen
START = time.time()
SIZE  = 10**6

factors = pfactor_gen(SIZE)

for i in xrange(2,SIZE,2):
  if sum(divisors(i)) % i == i/2:
    print i, factor(i)

print "Time Taken:", time.time() - START


"""
2: 1,3,7,15,31,65,129
3: 1,4,10,40,121,364
5: 1,6,31,156,781,3906

p(2)    = 3/2 -> 1 1/2
p(24)   = (13 * 4)/8 = 6 1/2
p(4320) = (63 * 40 * 6) = 3 1/2
        -> 2^4 * 3^3 * 5 * 7
  4320  = 2^5 * 3^3 * 5



2 [2]
24 [2, 2, 2, 3]
4320 [2, 2, 2, 2, 2, 3, 3, 3, 5]
4680 [2, 2, 2, 3, 3, 5, 13]
コード例 #3
0
def presents(n):
    s = 0
    for divisor in divisors(n):
        if n / divisor <= 50:
            s += divisor
    return s * 11
コード例 #4
0
ファイル: problem-012.py プロジェクト: jaspervdj/euler
def num_divisors(n):
    return sum(1 for _ in primes.divisors(n))
コード例 #5
0
from primes import divisors

count = 19423091

fronta = range(1, count + 1)

c = 0
while len(fronta) > 1:
    c += 1
    to_remove = []
    l = len(fronta)
    for d in divisors(l):
        if d > 1:
            x = d
            while x <= l:
                to_remove.append(fronta[x - 1])
                x += d
    to_remove = set(to_remove)
    new = []
    for f in fronta:
        if f not in to_remove:
            new.append(f)
    fronta = new
    print(c, len(fronta))
    if (len(fronta) < 100):
        print fronta

print(fronta, c)
コード例 #6
0
ファイル: prob583.py プロジェクト: mercurium/proj_euler
for m in xrange(1,1000):
    print m
    for n in xrange(1,m):
        h1 = m**2 - n**2
        w  = 2*m*n
        d2 = m**2 + n**2

        if h1*2 + w*2 > SIZE:
            break

        for i in xrange(2):
            if w % 4 != 0:
                h1, w = w,h1
                continue
            for a in divisors(w/4):
                for c in divisors(w/ (4*a)):
                    b = w / (4*a * c)
                    if a <= b:
                        break
                    h2 = (a**2 - b**2) * c
                    d1 = (a**2 + b**2) * c

                    if h2 > h1:
                        continue

                    if isSquare((h1+h2)**2 + (w/2)**2):
                        print "AB:", h1, "BD:", w, "BC:", d1, "Mult:", c
                        if (h1*2 + w + d1*2) <= SIZE:
                            total += h1*2 + w + d1 * 2
コード例 #7
0
ファイル: prob281.py プロジェクト: mercurium/proj_euler
import time, math
from primes import divisors, totient

START = time.time()
LIM   = 10**15

sumz  = 0
for m in xrange(2,20):
  for n in xrange(1,30):
    num_sum = 0
    for d in divisors(n):
      num_sum += totient(n/d) * math.factorial(m*d) / math.factorial(d)**m
    num_sum /= m*n
    if num_sum < LIM:
      sumz += num_sum
    else:
      break
  if n == 1:
    break

print "Answer:", sumz
print "Time Taken:", time.time() - START


"""
Congratulations, the answer you gave to problem 281 is correct.

You are the 611th person to have solved this problem.


t(1,n) = 1
コード例 #8
0
ファイル: prob241.py プロジェクト: mercurium/proj_euler
import time
from primes import divisors, factor, pfactor_gen
START = time.time()
SIZE = 10**6

factors = pfactor_gen(SIZE)

for i in xrange(2, SIZE, 2):
    if sum(divisors(i)) % i == i / 2:
        print i, factor(i)

print "Time Taken:", time.time() - START
"""
2: 1,3,7,15,31,65,129
3: 1,4,10,40,121,364
5: 1,6,31,156,781,3906

p(2)    = 3/2 -> 1 1/2
p(24)   = (13 * 4)/8 = 6 1/2
p(4320) = (63 * 40 * 6) = 3 1/2
        -> 2^4 * 3^3 * 5 * 7
  4320  = 2^5 * 3^3 * 5



2 [2]
24 [2, 2, 2, 3]
4320 [2, 2, 2, 2, 2, 3, 3, 3, 5]
4680 [2, 2, 2, 3, 3, 5, 13]
26208 [2, 2, 2, 2, 2, 3, 3, 7, 13]
コード例 #9
0
ファイル: prob583.py プロジェクト: mercurium/proj_euler
for m in xrange(1, 1000):
    print m
    for n in xrange(1, m):
        h1 = m**2 - n**2
        w = 2 * m * n
        d2 = m**2 + n**2

        if h1 * 2 + w * 2 > SIZE:
            break

        for i in xrange(2):
            if w % 4 != 0:
                h1, w = w, h1
                continue
            for a in divisors(w / 4):
                for c in divisors(w / (4 * a)):
                    b = w / (4 * a * c)
                    if a <= b:
                        break
                    h2 = (a**2 - b**2) * c
                    d1 = (a**2 + b**2) * c

                    if h2 > h1:
                        continue

                    if isSquare((h1 + h2)**2 + (w / 2)**2):
                        print "AB:", h1, "BD:", w, "BC:", d1, "Mult:", c
                        if (h1 * 2 + w + d1 * 2) <= SIZE:
                            total += h1 * 2 + w + d1 * 2
コード例 #10
0
ファイル: prob281.py プロジェクト: mercurium/proj_euler
import time, math
from primes import divisors, totient

START = time.time()
LIM = 10**15

sumz = 0
for m in xrange(2, 20):
    for n in xrange(1, 30):
        num_sum = 0
        for d in divisors(n):
            num_sum += totient(n / d) * math.factorial(
                m * d) / math.factorial(d)**m
        num_sum /= m * n
        if num_sum < LIM:
            sumz += num_sum
        else:
            break
    if n == 1:
        break

print "Answer:", sumz
print "Time Taken:", time.time() - START
"""
Congratulations, the answer you gave to problem 281 is correct.

You are the 611th person to have solved this problem.


t(1,n) = 1
t(2,n) = OEIS series here: https://oeis.org/A003239
コード例 #11
0
ファイル: problem21.py プロジェクト: ganzevoort/project-euler
def d(n):
    proper_divisors = divisors(n)[:-1]
    return sum(proper_divisors)