コード例 #1
0
ファイル: a.py プロジェクト: msbelal/Project-Euler
#    return n

#def find_factors(n) :
#    factors = []
#    while n != 1 :
#        fac = find_factor(n)
#        if fac not in factors :
#            factors.append(fac)
#        n /= fac
#    return factors

import psyco
psyco.full()

import primes
pt = primes.primeTable(1000 * 1000)


def find_factors(n):
    factors = set()
    while pt[n] != 1:
        factors.add(pt[n])
        n /= pt[n]
    factors.add(n)
    return factors


def totient(n):
    num, denom = 1, 1
    for factor in find_factors(n):
        num *= (factor - 1)
コード例 #2
0
ファイル: a.py プロジェクト: hughdbrown/Project-Euler
#    return n
    
#def find_factors(n) :
#    factors = []
#    while n != 1 :
#        fac = find_factor(n)
#        if fac not in factors :
#            factors.append(fac)
#        n /= fac
#    return factors

import psyco
psyco.full()

import primes
pt = primes.primeTable(1000*1000)

def find_factors(n) :
	factors = set()
	while pt[n] != 1 :
		factors.add(pt[n])
		n /= pt[n]
	factors.add(n)
	return factors

def totient(n) :
	num, denom = 1, 1
	for factor in find_factors(n) :
		num *= (factor - 1)
		denom *= factor
	return (n * num) / denom
コード例 #3
0
ファイル: euler-70(2).py プロジェクト: msbelal/Project-Euler
import phi
import sys
"""
21 21 12 1.75 [3, 7]
291 291 192 1.515625 [3, 97]
2817 2817 1872 1.50480769231 [3, 3, 313]
2991 2991 1992 1.5015060241 [3, 997]
4435 4435 3544 1.25141083521 [5, 887]
20617 20617 20176 1.02185765266 [53, 389]
45421 45421 44512 1.02042145938 [53, 857]
69271 69271 67912 1.02001119095 [53, 1307]
"""

import primes
limit = 10 * 1000 * 1000
pt = primes.primeTable(limit)


def find_factors(n):
    factors = set()
    while pt[n] != 1:
        factors.add(pt[n])
        n /= pt[n]
    factors.add(n)
    return factors


def totient(n):
    num, denom = 1, 1
    for factor in find_factors(n):
        num *= (factor - 1)
コード例 #4
0
import sys

"""
21 21 12 1.75 [3, 7]
291 291 192 1.515625 [3, 97]
2817 2817 1872 1.50480769231 [3, 3, 313]
2991 2991 1992 1.5015060241 [3, 997]
4435 4435 3544 1.25141083521 [5, 887]
20617 20617 20176 1.02185765266 [53, 389]
45421 45421 44512 1.02042145938 [53, 857]
69271 69271 67912 1.02001119095 [53, 1307]
"""

import primes
limit = 10*1000*1000
pt = primes.primeTable(limit)

def find_factors(n) :
	factors = set()
	while pt[n] != 1 :
		factors.add(pt[n])
		n /= pt[n]
	factors.add(n)
	return factors

def totient(n) :
	num, denom = 1, 1
	for factor in find_factors(n) :
		num *= (factor - 1)
		denom *= factor
	return (n * num) / denom