結果

問題 No.747 循環小数N桁目 Hard
ユーザー Haar
提出日時 2018-11-11 22:02:31
言語 Haskell
(9.10.1)
結果
WA  
実行時間 -
コード長 514 bytes
コンパイル時間 11,815 ms
コンパイル使用メモリ 169,728 KB
実行使用メモリ 13,824 KB
最終ジャッジ日時 2024-12-15 00:20:36
合計ジャッジ時間 12,849 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 100 WA * 20
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.8.2/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )
[2 of 2] Linking a.out

ソースコード

diff #

import Data.Char

main = do
  n <- getLine
  k <- getLine
  let r = [2,8,5,7,1,4]
  
  print $ r !! ((powerMod (modBigInteger n 6) (modBigInteger k 6) 6 + 5) `mod` 6)

modBigInteger :: String -> Int -> Int
modBigInteger [] _ = 0
modBigInteger xs m = foldl (\x y -> (x*10 + y) `mod` m) 0 (map digitToInt xs)

powerMod :: Integral a => a -> a -> a -> a
powerMod n 0 m = 1
powerMod n 1 m = n `mod` m
powerMod n p m = ((k * k) `mod` m * (if mod p 2 == 0 then 1 else n)) `mod` m
  where
    k = powerMod n (div p 2) m

0