You are viewing a single comment's thread. Return to all comments →
Haskell, used Euclid's Formula
import Control.Applicative import Control.Monad import System.IO import Data.Set py_trips :: Int -> [Int] py_trips max = [x * y * z * (max `div` (x+y+z))^3 | m <- [2..(max `div` 6)], n <- [1..(max `div` 12)], m > n, let x = ((m*m) - (n*n)), let y = (2*m*n), let z = ((m*m) + (n*n)), max `mod` (x+y+z) == 0] py_max :: [Int] -> Int py_max [] = -1 py_max n = maximum 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 trips = py_max (py_trips n) print (trips)
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #9: Special Pythagorean triplet
You are viewing a single comment's thread. Return to all comments →
Haskell, used Euclid's Formula