Пример #1
0
# -*- coding: utf-8 -*-
# vim: ai ts=4 sts=4 et sw=4
"""
145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145.

Find the sum of all numbers which are equal to the sum of the 
factorial of their digits.

Note: as 1! = 1 and 2! = 2 are not sums they are not included.
"""
from fast_prime import factorial

facts = dict((n, factorial(n)) for n in range(10))

def solve():
    s = 0
    for n in xrange(3, 100000):
        if sum((facts[int(d)] for d in str(n))) == n:
            s+=n
            print n
        if n % 1000000 == 0: 
            print n
    print "Answer: ", s

#test() 
solve()

Пример #2
0
        c = count_factors(n)
        n += 10
        if c > highest[0]: 
            highest = (c, n)
    print n-1

if __name__=="__main__":
##    for s in solutions(4):
##        print '1/%i + 1/%i = 1/%i' % s
    assert solutions(4) == 3
    
    if 0:
        import cProfile
        cProfile.run('solve()')
    elif 0:
        f = factorial(12)
        f2 = factorial(13)
        print f, f2
        print f2 - f
        print len([n for n in primes_in_range(f+1, f+10000)])
    elif 0:
        factor_search(50)
    elif 1:
        solve(1000000)
    elif 0:
        import time
        def cfs():
            c = 1
            vals = []
            while c < 10000:
                vals.append(count_factors(c))
Пример #3
0
"""
2007-12-20
n! means n  (n  1)  ...  3  2  1

Find the sum of the digits in the number 100!
"""

import psyco
psyco.full()
from fast_prime import factorial

print sum(map(int, [l for l in str(factorial(100))]))


# 648