結果
問題 | No.181 A↑↑N mod M |
ユーザー | こまる |
提出日時 | 2020-10-24 05:05:42 |
言語 | Haskell (9.8.2) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,241 bytes |
コンパイル時間 | 1,010 ms |
コンパイル使用メモリ | 163,032 KB |
実行使用メモリ | 7,604 KB |
最終ジャッジ日時 | 2023-09-28 20:07:22 |
合計ジャッジ時間 | 2,953 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
7,432 KB |
testcase_01 | AC | 2 ms
7,448 KB |
testcase_02 | AC | 2 ms
6,984 KB |
testcase_03 | AC | 2 ms
7,056 KB |
testcase_04 | AC | 2 ms
7,560 KB |
testcase_05 | AC | 3 ms
7,604 KB |
testcase_06 | AC | 3 ms
7,340 KB |
testcase_07 | AC | 3 ms
7,472 KB |
testcase_08 | AC | 2 ms
7,564 KB |
testcase_09 | AC | 2 ms
7,392 KB |
testcase_10 | AC | 2 ms
7,432 KB |
testcase_11 | AC | 3 ms
7,424 KB |
testcase_12 | AC | 3 ms
7,444 KB |
testcase_13 | AC | 3 ms
7,540 KB |
testcase_14 | AC | 3 ms
7,444 KB |
testcase_15 | AC | 3 ms
7,432 KB |
testcase_16 | AC | 3 ms
7,128 KB |
testcase_17 | AC | 3 ms
7,464 KB |
testcase_18 | AC | 3 ms
7,052 KB |
testcase_19 | AC | 3 ms
6,980 KB |
testcase_20 | AC | 3 ms
6,936 KB |
testcase_21 | AC | 3 ms
6,960 KB |
testcase_22 | AC | 3 ms
6,928 KB |
testcase_23 | AC | 3 ms
7,396 KB |
testcase_24 | AC | 3 ms
7,568 KB |
testcase_25 | AC | 3 ms
7,484 KB |
testcase_26 | AC | 2 ms
7,572 KB |
testcase_27 | AC | 3 ms
7,468 KB |
testcase_28 | AC | 2 ms
7,416 KB |
testcase_29 | AC | 3 ms
7,448 KB |
testcase_30 | AC | 3 ms
7,584 KB |
testcase_31 | AC | 2 ms
7,564 KB |
testcase_32 | WA | - |
testcase_33 | AC | 3 ms
7,436 KB |
testcase_34 | AC | 3 ms
7,508 KB |
testcase_35 | AC | 3 ms
7,544 KB |
testcase_36 | AC | 2 ms
7,496 KB |
testcase_37 | AC | 3 ms
7,460 KB |
testcase_38 | AC | 3 ms
7,480 KB |
testcase_39 | AC | 2 ms
7,360 KB |
testcase_40 | AC | 3 ms
7,528 KB |
testcase_41 | AC | 2 ms
7,400 KB |
testcase_42 | AC | 2 ms
7,496 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 ) Main.hs:24:37: warning: [GHC-68441] [-Wdeprecations] In the use of ‘powModInteger’ (imported from GHC.Integer.GMP.Internals): Deprecated: "Use integerPowMod# instead" | 24 | powModInt a b c = fromInteger $ GMP.powModInteger (fromIntegral a) (fromIntegral b) (fromIntegral c) | ^^^^^^^^^^^^^^^^^ [2 of 2] Linking a.out
ソースコード
{-# LANGUAGE BangPatterns #-} import Data.Bool import Data.List import qualified GHC.Integer.GMP.Internals as GMP main :: IO () main = do [a, b, n] <- map read . words <$> getLine print $ tetration a b n tetration :: Int -> Int -> Int -> Int tetration a b m | m == 1 = 0 | a == 0 = bool 0 1 (even b) | b == 0 = 1 | b == 1 = a `mod` m | b == 2 = powModInt (a `mod` m) a m | otherwise = powModInt (a `mod` m) (prev + phi) m where !phi = totient m prev = tetration a (b - 1) phi powModInt :: Int -> Int -> Int -> Int powModInt a b c = fromInteger $ GMP.powModInteger (fromIntegral a) (fromIntegral b) (fromIntegral c) {-# INLINE powModInt #-} totient :: Int -> Int totient n = n `quot` product ps * (product $ map (subtract 1) ps) where ps = map head . group $ primeFactors n smallPrimes :: [Int] smallPrimes = 2 : [n | n <- [3, 5 .. 46337], all ((0 <) . rem n) $ takeWhile (\x -> x * x <= n) smallPrimes] primeFactors :: Int -> [Int] primeFactors n | n < 2 = [] primeFactors n = go n smallPrimes where go !n pps@(p:ps) | n < p * p = [n] | r > 0 = go n ps | otherwise = p : go q pps where (q, r) = quotRem n p go n [] = [n]