  1
  | otherwise        = -1
  where is = [i | (_, i) <- factorize n]


-----------------------------------------
-- 2 進表現のビット数を返す
-----------------------------------------
binarySize :: Integral a => a -> Int
binarySize = length . integralToList 2


-----------------------------------------
-- ペル方程式
-----------------------------------------
--
-- + "x^2 - d * y^ = 1" の解 (x, y) (x > 1, y > 1) を小さい順に返す。
--
-- + from http://www004.upp.so-net.ne.jp/s_honma/pell/pell.htm
--
pell'sEquation :: Integer -> [(Integer, Integer)]
pell'sEquation d = iterate (f (x, y)) (x, y)
  where
    f (a1, b1) (a2, b2) = (a1 * a2 + 
phi :: Integral a => a -> a
phi n = product [p^(i - 1) * (p - 1) | (p, i) <- factorize n]
phi n = product [p^(i - 1) * (p - 1) | (p, i) <- factorize n]