Esempio n. 1
0
def solve_twodigit():
    for n in xrange(99*99, 1, -1):
##        if n < 9000:
##            break
        if ispalindrome(n) and not isprime(n):
#            print 'checking',n
            for x in factors(n):
                if x <= 99 and x >= 10 and n / x > 10 and n / x < 99:
                    print n, ':', x, '*', n / x
                    break
Esempio n. 2
0
    i = 1
    s = 0
    while True:
        s = s + i
        i += 1
        yield s

## demo
#c=0
#for x in tris():
#    if c >= 7:
#        break
#    print '%2i: %s' % (x, ','.join(map(str, [f for f in factors(x)])))
#    c+=1

m = 0
n = 1
t = tris()
while m < 500:
    c = t.next()
    m = max(m, count_factors(c))
    n+=1
    if n % 200==0:
        print n
print '%2i: %s' % (c, ','.join(map(str, [f for f in factors(c)])))
# 11800
# 12000
# 12200
#76576500

Esempio n. 3
0
though it is known that the greatest number that cannot be expressed as 
the sum of two abundant numbers is less than this limit. 

Find the sum of all the positive integers which cannot be written as the 
sum of two abundant numbers. 
"""

import psyco
psyco.full()

import fast_prime as fp

mrange = 28124
abunds = {}
for i in range(1, mrange):
    fs = [f for f in fp.factors(i)][:-1]
    s = sum(fs)
    if s > i:
        abunds[i] = 0
nsum = []
for n in range(1, mrange):
    found = False
    for k in abunds:
        if n - k in abunds:
            found = True
            break
    if not found:
        nsum.append(n)
print len(nsum), sum(nsum)

# 1456 abundants, sum = 4179871
Esempio n. 4
0
            c = 1
            vals = []
            while c < 10000:
                vals.append(count_factors(c))
                c += 1
            return vals
        def sols():
            c = 1
            vals = []
            while c < 10000:
                vals.append(solutions(c))
                c += 1
            return vals
        s = time.time()
        sols()
        print "solutions in", time.time() - s

        s = time.time()
        cfs()
        print "count factors in", time.time() - s
    else:
        m = 10000
        v = dict((n, solutions(n)) for n in range(1, m+1))
        v2 = dict((n, count_factors(n)) for n in range(1,m+1))
        for i in v:
            if v[i] != v2[i]:
                print '%-4i: %-3i%i' % (i, v[i], v2[i])
                print '  ', ','.join(map(str, [f for f in factors(i)]))
                print '  ', ','.join(map(str, [f for f in psolutions(i)]))

Esempio n. 5
0
"""
2007-12-14

The prime factors of 13195 are 5, 7, 13 and 29.

What is the largest prime factor of the number 317584931803?

    >>> for x in factors(13195):
    ...     if isprime(x):
    ...         print '%i,'%x , 

    5, 7, 13, 29,

"""

from fast_prime import factors, isprime

for x in factors(317584931803):
    if isprime(x):
        print "%i," % x,
# 1, 67, 829, 1459, 3919