結果

問題 No.403 2^2^2
ユーザー pekempey
提出日時 2016-07-28 23:35:36
言語 Haskell
(9.10.1)
結果
WA  
実行時間 -
コード長 616 bytes
コンパイル時間 1,896 ms
コンパイル使用メモリ 171,736 KB
実行使用メモリ 820,256 KB
最終ジャッジ日時 2024-11-06 18:16:21
合計ジャッジ時間 6,750 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 13 WA * 5 MLE * 1 -- * 8
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 Control.Applicative
import Control.Monad
import Data.List

replace x = map (\ c -> if c == x then ' ' else c)

modpow x y m
    | y == 0         = 1
    | y `mod` 2 == 0 = modpow ((x * x) `rem` m) (y `quot` 2) m
    | otherwise      = (x * modpow x (y - 1) m) `rem` m

solve1 a b c m
    | a == 0    = 0
    | otherwise = modpow (modpow a b m) c m

solve2 a b c m
    | a == 0    = 0
    | otherwise = modpow a (modpow b c (m - 1)) m

main = do
    [a, b, c] <- map read . words . replace '^' <$> getLine :: IO [Int]
    let m = 10 ^ 9 + 7
    putStrLn $ show (solve1 a b c m) ++ " " ++ show (solve2 a b c m)
0