:: Integral a => a -> [(a, a, a)]
pythagoreanNums n
    | odd n     = []
    | otherwise = [(a, b, n - a - b) | a <- as, let b = calc a, a < b]
    where
      as = [a | a <- [1 .. div n 3], rem (a * n) (2 * (n - a)) == 0]
      calc a = div (n * (n - 2 * a)) (2 * (n - a))

--
-- 既約ピタゴラス数
--
primitivePythagoreanNums :: Integral a => a -> [(a, a, a)]
primitivePythagoreanNums n =
    [(a, b, c) | (a, b, c) <- pythagoreanNums n, gcd a b == 1]



-----------------------------------------
-- 順列と組み合わせ
-----------------------------------------

--
-- 順列の数
--
-- ex : permutationSize 5 3 => 60
--
permutationSize :: Integral a => a -> a -> a
permutationSize = fallingFactorial

--
-- 組み合わせの数
--
-- ex : combinationSize 5 3 => 10
--
combinationSize :: Integral a => a -> a -> a
combinationSize m n = div (fallingFactorial m n) (factorial n)



-----------------------------------------
-- その他
-----------------------------------------

--
-- 平方根の整数部分
--
isqrt :: Integral a => a -> a
isqrt =
pythagoreanNums :: Integral a => a -> [(a, a, a)]
pythagoreanNums n
    | odd n     = []
    | otherwise = [(a, b, n - a - b) | a <- as, let b = calc a, a < b]
    where
      as = [a | a <- [1 .. div n 3], rem (a * n) (2 * (n - a)) == 0]
      calc a = div (n * (n - 2 * a)) (2 * (n - a))

--
-- 既約ピタゴラス数
--
pythagoreanNums n
    | odd n     = []
    | otherwise = [(a, b, n - a - b) | a <- as, let b = calc a, a < b]
    where
      as = [a | a <- [1 .. div n 3], rem (a * n) (2 * (n - a)) == 0]
      calc a = div (n * (n - 2 * a)) (2 * (n - a))

--
-- 既約ピタゴラス数
--