結果

問題 No.16 累乗の加算
ユーザー くれちーくれちー
提出日時 2017-02-14 18:47:42
言語 Haskell
(9.8.2)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 585 bytes
コンパイル時間 839 ms
コンパイル使用メモリ 160,824 KB
実行使用メモリ 8,192 KB
最終ジャッジ日時 2023-09-08 12:05:35
合計ジャッジ時間 1,887 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,032 KB
testcase_01 AC 2 ms
7,132 KB
testcase_02 AC 4 ms
8,192 KB
testcase_03 AC 3 ms
7,300 KB
testcase_04 AC 3 ms
7,484 KB
testcase_05 AC 3 ms
7,500 KB
testcase_06 AC 3 ms
7,764 KB
testcase_07 AC 4 ms
7,572 KB
testcase_08 AC 3 ms
7,980 KB
testcase_09 AC 4 ms
8,052 KB
testcase_10 AC 4 ms
7,816 KB
testcase_11 AC 2 ms
7,196 KB
testcase_12 AC 4 ms
7,636 KB
testcase_13 AC 4 ms
7,388 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 #

import Control.Applicative ((<$>))

mod'' :: Integral a => a -> a
mod'' = flip mod 1000003

modPow :: Integral a => a -> a -> a
modPow x n
    | n == 0 = 1
    | even n = mod'' $ modPow (x' ^ 2) (n `div` 2)
    | odd n  = mod'' $ x' * modPow x' (n - 1)
    where
        x' = mod'' x

modSum :: Integral a => [a] -> a
modSum (x : []) = mod'' $ x
modSum (x : xs) = mod'' $ x + modSum xs

solve :: Integral a => a -> [a] -> a
solve x as = modSum $ map (x `modPow`) as

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