結果

問題 No.16 累乗の加算
ユーザー gemmarogemmaro
提出日時 2020-08-07 08:42:31
言語 Haskell
(9.8.2)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 459 bytes
コンパイル時間 5,857 ms
コンパイル使用メモリ 165,292 KB
実行使用メモリ 5,976 KB
最終ジャッジ日時 2023-10-23 23:11:06
合計ジャッジ時間 7,093 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,276 KB
testcase_01 AC 2 ms
5,276 KB
testcase_02 AC 3 ms
5,976 KB
testcase_03 AC 2 ms
5,436 KB
testcase_04 AC 2 ms
5,476 KB
testcase_05 AC 2 ms
5,524 KB
testcase_06 AC 3 ms
5,704 KB
testcase_07 AC 2 ms
5,600 KB
testcase_08 AC 3 ms
5,800 KB
testcase_09 AC 3 ms
5,880 KB
testcase_10 AC 3 ms
5,688 KB
testcase_11 AC 2 ms
5,284 KB
testcase_12 AC 3 ms
5,652 KB
testcase_13 AC 3 ms
5,516 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.6.2/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )
[2 of 2] Linking a.out

ソースコード

diff #

main :: IO ()
main = do
    [x, n] <- map read . words <$> getLine
    as <- map read . words <$> getLine
    print $ solve x n as

solve :: Int -> Int -> [Int] -> Int
solve x n as =
    sum (map solve' as) `mod` l
        where
            l = 10 ^ 6 + 3
            solve' :: Int -> Int
            solve' 0 = 1
            solve' a
              | odd a = (h * x) `mod` l
              | otherwise = h `mod` l
              where h = solve' (a `div` 2) ^ 2
0