2012. 2. 19. 02:21
def factorize(n):
    def isPrime(n):
        return not [x for x in xrange(2,int(math.sqrt(n)))
                    if n%x == 0]
    primes = []
    candidates = xrange(2,n+1)
    candidate = 2
    while not primes and candidate in candidates:
        if n%candidate == 0 and isPrime(candidate):
            primes = primes + [candidate] + factorize(n/candidate)
        candidate += 1            
    return primes

'python' 카테고리의 다른 글

빠른 소인수 분해  (0) 2012.02.19
라빈 밀러 소수판별  (0) 2012.02.19
긴 문자열을 숫자로 바꾸는 코드  (0) 2012.02.19
[python] (가명) 속성 및 연산자 메쏘드  (0) 2011.11.12
[python] 비트맵 bitmap 쓰기  (0) 2011.11.04
Posted by Нуеоп