module Problem130 where

import Prime

main :: IO ()
main = print . sum . take 25 . filter (\n -> (n - 1) `mod` a n == 0) $ filter
    (\x -> not (isPrimeNaive x) && gcd x 10 == 1)
    [2 ..]
  where
    a :: Int -> Int
    a = go 1
    go v n = case (10 * v + 1) `rem` n of
        0 -> 2
        r -> 1 + go r n
