Exemple #1
0
'''
Created on 23.05.2012

@author: AN
'''
from pylib import nums

primes = [p for p in nums.primes_sieve(12000)]
factorization = {i: nums.factorize(i, primes) for i in xrange(2, 12001)}
set_factorization = nums.factorize_to_set(factorization)

print nums.euler_phi(9, set_factorization)
Exemple #2
0
'''
Created on 23.05.2012

@author: AN
'''

from pylib import nums

primes = [p for p in nums.primes_sieve(13)]

cache = {}
def dp(n, index):
    prime = primes[index]
    sq = prime * prime
    if sq > n:
        return 0
    if (n, index) in cache:
        return cache[(n, index)]
    else:
        result = dp(n / sq, index)
        if index < len(primes) - 1:
            result += dp(n, index + 1)
        cache[(n, index)] = result
        return result
    
    
print dp(12, 0)