結果

問題 No.1252 数字根D
ユーザー こまるこまる
提出日時 2020-10-20 11:53:25
言語 Haskell
(9.8.2)
結果
AC  
実行時間 22 ms / 2,000 ms
コード長 836 bytes
コンパイル時間 923 ms
コンパイル使用メモリ 160,272 KB
実行使用メモリ 11,224 KB
最終ジャッジ日時 2023-09-28 13:40:10
合計ジャッジ時間 2,538 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,088 KB
testcase_01 AC 4 ms
7,644 KB
testcase_02 AC 4 ms
8,768 KB
testcase_03 AC 12 ms
11,144 KB
testcase_04 AC 22 ms
11,212 KB
testcase_05 AC 22 ms
11,156 KB
testcase_06 AC 22 ms
11,112 KB
testcase_07 AC 22 ms
11,128 KB
testcase_08 AC 22 ms
11,176 KB
testcase_09 AC 22 ms
11,224 KB
testcase_10 AC 22 ms
11,116 KB
testcase_11 AC 22 ms
11,116 KB
testcase_12 AC 22 ms
11,204 KB
testcase_13 AC 22 ms
11,184 KB
testcase_14 AC 3 ms
7,288 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.6.1/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )
[2 of 2] Linking a.out

ソースコード

diff #

{-# LANGUAGE BangPatterns #-}
import qualified Data.Vector.Fusion.Stream.Monadic as VFSM
main :: IO ()
main = do
  q <- readLn :: IO Int
  rep q $ \_ -> do
    [d, a, b] <- map (read :: String -> Int) . words <$> getLine
    if a == 0
      then print $ func b d - func 0 d
      else print $ func b d - func (a - 1) d

func :: Int -> Int -> Int
func x d =
  let
    (q, r) = divMod x (d - 1)
  in
    d * (d - 1) `div` 2 * q + r * (r + 1) `div` 2

stream :: Monad m => Int -> Int -> VFSM.Stream m Int
stream !l !r = VFSM.Stream step l
  where
    step x
      | x < r     = return $ VFSM.Yield x (x + 1)
      | otherwise = return $ VFSM.Done
    {-# INLINE [0] step #-}
{-# INLINE [1] stream #-}

-- | rep 10 -> 0 1 2 3 4 5 6 7 8 9
rep :: Monad m => Int -> (Int -> m ()) -> m ()
rep n = flip VFSM.mapM_ (stream 0 n)
{-# INLINE rep #-}
0