* Computer Science/Project Euler

project euler 3. problem

soicem 2016. 7. 13. 09:29

문제 : 어떤 수를 소수의 곱으로만 나타내는 것을 소인수분해라 하고, 이 소수들을 그 수의 소인수라고 합니다.

예를 들면 13195의 소인수는 5, 7, 13, 29 입니다.

600851475143의 소인수 중에서 가장 큰 수를 구하세요.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
def IntFacto(mod):
    
    result = 1
    i =1 
    while i<mod:
        if mod % i ==0:
            modCnt=0
            for j in range(1, i+1):
                
                if i%j==0:
                    modCnt+=1
                else:
                    continue
            if modCnt==2:
                print "mod : %d" % i
                result *= i
                print "result : %d" % result
            elif result == mod:
                break
        i+=1
 
IntFacto(600851475143)
cs

C:\Users\soicem's com\Desktop>python test.py

mod : 71

result : 71

mod : 839

result : 59569

mod : 1471

result : 87625999

mod : 6857

result : 600851475143


'* Computer Science > Project Euler' 카테고리의 다른 글

project euler 5. problem  (0) 2016.07.15
project euler 4. problem  (0) 2016.07.14
project euler 2. problem  (0) 2016.07.12
project euler 1. problem  (0) 2016.07.11
codeground 2번. 프로그래밍 경진대회  (0) 2016.06.02