結果
| 問題 |
No.344 ある無理数の累乗
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-11-07 09:32:47 |
| 言語 | Haskell (9.10.1) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 610 bytes |
| コンパイル時間 | 8,658 ms |
| コンパイル使用メモリ | 170,624 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-22 14:21:36 |
| 合計ジャッジ時間 | 8,531 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 30 |
コンパイルメッセージ
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
ソースコード
modulo :: Int
modulo = 1000
{-# INLINE modulo #-}
type Number = (Int, Int)
infixr 8 @^@
infixl 7 @*@
(@*@) :: Number -> Number -> Number
(ap, aq) @*@ (bp, bq) = ((ap * bp + 3 * aq * bq) `mod` modulo, (ap * bq + aq * bp) `mod` modulo)
{-# INLINE (@*@) #-}
(@^@) :: Number -> Int -> Number
a @^@ i
| i == 0 = (1, 0)
| odd i = res @*@ a
| otherwise = res
where
res :: Number
res = (a @*@ a) @^@ (div i 2)
{-# INLINE (@^@) #-}
main :: IO ()
main = do
n <- readLn :: IO Int
let x = (1, 1) @^@ n
print $ if even n then ((fst x) * 2 - 1) `mod` modulo else ((fst x) * 2) `mod` modulo