Skip to content

Instantly share code, notes, and snippets.

@kanedo
Created December 19, 2012 20:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kanedo/4340052 to your computer and use it in GitHub Desktop.
Save kanedo/4340052 to your computer and use it in GitHub Desktop.
Fermat's little theorem
fermat :: (Integral i, Show i) => i -> Bool
fermat 1 = True -- Fermat's litte theorem only works for
fermat 2 = True -- numbers greater then 2
fermat x = not (null [x | y<-[2.. pred x], (y^(x-1) `mod` x) == 1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment