LoginSignup
2
2

More than 5 years have passed since last update.

Project Euler 問題3 「600851475143の最大の素因数」

Posted at

問題

600851475143 の最大の素因数を求めよ。

The prime factors of 13195 are 5, 7, 13 and 29.
What is the largest prime factor of the number 600851475143 ?

コード

def divideByFactor(factor, num):
  while(num % factor == 0): #割り切れなくなるまで割る
    num /= factor
  return factor, num

num = 600851475143
factor =1

while num >= factor:
  factor += 1
  factor, num = divideByFactor(factor, num)

print(factor)
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2