結果
問題 |
No.16 累乗の加算
|
ユーザー |
![]() |
提出日時 | 2017-02-14 18:47:42 |
言語 | Haskell (9.10.1) |
結果 |
AC
|
実行時間 | 3 ms / 5,000 ms |
コード長 | 585 bytes |
コンパイル時間 | 4,421 ms |
コンパイル使用メモリ | 172,160 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-26 05:20:03 |
合計ジャッジ時間 | 5,106 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 14 |
コンパイルメッセージ
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
ソースコード
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