Skip to content

Instantly share code, notes, and snippets.

@jlfwong
Created January 30, 2011 03:09
Show Gist options
  • Save jlfwong/802478 to your computer and use it in GitHub Desktop.
Save jlfwong/802478 to your computer and use it in GitHub Desktop.
keepDiv :: Int -> Int -> Int
keepDiv x n
| x `mod` n == 0 = keepDiv (x `div` n) n
| otherwise = x
nfacts' :: Int -> Int -> Int
nfacts' 1 _ = 0
nfacts' x n
| x `mod` n == 0 = 1 + nfacts' (x `keepDiv` n) (n + 1)
| otherwise = nfacts' x (n + 1)
nfacts :: Int -> Int
nfacts x = nfacts' x 2
solve :: [Int] -> Int
solve [a,b,n] = length $ filter (\x -> nfacts x == n) [a..b]
input :: [String] -> String
input [] = ""
input x = show $ solve $ map readInt x
readInt :: String -> Int
readInt x = read x :: Int
main = do interact $ unlines . map (input . words) . tail . lines
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment