LoginSignup
1
1

More than 5 years have passed since last update.

Project Euler No. 3

Posted at

Problem

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

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

Haskell Code

Euler_003.hs
module Main where
import Data.List

-- (x:xs)は自然数の列で、小さい方からnを除算をしていく。
-- 剰余が0ならもう一度その同じ数で除算し、
-- そうでないなら次の自然数で除算するという再帰。

factoring n fs (x:xs)
  | n == 1 = fs
  | (mod n x == 0) = factoring (div n x) (x:fs) (x:xs)
  |otherwise = factoring n fs xs

main = print answer
  where 
    answer = maximum $ factoring n [] [2..n]
    n = 600851475143

Answer

6**7

1
1
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
1
1