-
Notifications
You must be signed in to change notification settings - Fork 0
/
SPOJStrict.hs
53 lines (31 loc) · 1.3 KB
/
SPOJStrict.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env runhaskell
{-# LANGUAGE BangPatterns
#-}
{-| The Sphere Online Judge is a collection of problems. One problem, problem
450, came up on the mailing list as a sensible benchmark for fast integer
parsing.
-}
{- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
https://www.spoj.pl/problems/INTEST/
Slow IO?
http://www.nabble.com/Slow-IO--td25210251.html
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -}
import Data.List
import Prelude hiding (drop, take)
import System.IO (stdin, stdout, stderr, Handle, putStrLn)
import Control.Monad
import Data.ByteString hiding (putStrLn, foldl')
import Data.ByteString.Nums.Careless
main = do
(n, k) <- breakByte 0x20 `fmap` hGetLine stdin
count <- show `fmap` strict (int n) (int k)
putStrLn count
strict !n !k = sum `fmap` sequence (numbers n stdin)
where
sum = foldl' (check k) 0
numbers :: Int -> Handle -> [IO Int]
numbers !n !h = const (int `fmap` hGetLine h) `fmap` [1..n]
check :: Int -> Int -> Int -> Int
check !k !acc !n
| n `mod` k == 0 = acc + 1
| otherwise = acc