You are viewing a single comment's thread. Return to all comments →
Haskell
import Control.Applicative import Control.Monad import System.IO largestPrime :: [Int] -> Int -> Int largestPrime list max | (length list) == 1 = max | otherwise = last list factorize :: Int -> Int -> [Int] factorize _ 1 = [] factorize m n | m * m > n = [n] | n `mod` m == 0 = m : factorize m (n `div` m) | otherwise = factorize (m + 1) n main :: IO () main = do t_temp <- getLine let t = read t_temp :: Int forM_ [1..t] $ \a0 -> do n_temp <- getLine let n = read n_temp :: Int let factors = factorize 2 n putStrLn(show (largestPrime factors n))
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #3: Largest prime factor
You are viewing a single comment's thread. Return to all comments →
Haskell