コード例 #1
0
ファイル: 003.py プロジェクト: ametisf/projecteuler
#!/usr/bin/python3

"""
Problem 3 - Largest prime factor

The prime factors of 13195 are 5, 7, 13 and 29.

What is the largest prime factor of the number 600851475143 ?
"""

from modules.matlib import primeFactors

print(max(primeFactors(600851475143))) # output largest number from list of prime factors of number

コード例 #2
0
ファイル: 005.py プロジェクト: Destiny97/projecteuler
from modules.matlib import primeFactors

factors = []

for x in range(2, 21, 1):
    facts = primeFactors(x)
    for f in facts:
        for i in range(facts.count(f)-factors.count(f)): factors.append(f)

nsn = 1
for x in factors: nsn *= x

print(nsn)
コード例 #3
0
ファイル: project3.py プロジェクト: Destiny97/projecteuler
from modules.matlib import primeFactors

print(max(primeFactors(600851475143)))
コード例 #4
0
ファイル: 005.py プロジェクト: ametisf/projecteuler
#!/usr/bin/python3

"""
Problem 5 - Smallest multiple

2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.

What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?
"""

from modules.matlib import primeFactors

factors = []  # store factors

for x in range(2, 21, 1):  # for numbers from 2 to 20
    facts = primeFactors(x)  # list prime factors of x
    for f in facts:  # each prime factors of x
        for i in range(facts.count(f) - factors.count(f)):
            factors.append(f)  # append as many factors as this number has

nsn = 1  # smallest multiple
for x in factors:
    nsn *= x  # multiply all factors

print(nsn)  # output result