Skip to content

Instantly share code, notes, and snippets.

@amonshiz
Created January 9, 2016 22:04
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 amonshiz/75969479c3f951fdd191 to your computer and use it in GitHub Desktop.
Save amonshiz/75969479c3f951fdd191 to your computer and use it in GitHub Desktop.
permutationWithMod :: Integer -> Integer -> Integer -> Integer
permutationWithMod numTake setSize modValue =
let nums = [(setSize - numTake + 1)..setSize]
in foldl (\acc n -> (acc * n) `mod` modValue) 1 nums
main :: IO()
main = do
setSize <- getLine
numTake <- getLine
modValue <- getLine
print $ permutationWithMod (read numTake) (read setSize) (read modValue)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment