結果

問題 No.16 累乗の加算
ユーザー taktak
提出日時 2018-04-14 00:53:01
言語 F#
(F# 4.0)
結果
AC  
実行時間 86 ms / 5,000 ms
コード長 412 bytes
コンパイル時間 4,910 ms
コンパイル使用メモリ 154,476 KB
実行使用メモリ 24,868 KB
最終ジャッジ日時 2023-09-09 04:57:12
合計ジャッジ時間 5,477 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
22,784 KB
testcase_01 AC 86 ms
20,700 KB
testcase_02 AC 86 ms
24,828 KB
testcase_03 AC 86 ms
22,832 KB
testcase_04 AC 85 ms
22,848 KB
testcase_05 AC 86 ms
24,748 KB
testcase_06 AC 86 ms
22,948 KB
testcase_07 AC 86 ms
22,924 KB
testcase_08 AC 86 ms
23,024 KB
testcase_09 AC 86 ms
24,868 KB
testcase_10 AC 86 ms
24,832 KB
testcase_11 AC 86 ms
24,856 KB
testcase_12 AC 85 ms
22,868 KB
testcase_13 AC 86 ms
22,816 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) F# Compiler version 11.0.0.0 for F# 5.0
Copyright (c) Microsoft Corporation. All Rights Reserved.

ソースコード

diff #

let read() = stdin.ReadLine().Split() |> Array.map(int64)
let (|Odd|Even|) n = if n%2L=1L then Odd else Even
let modVal = 1000003L
let rec modPow x = function
    | 0L        -> 1L
    | Even as n -> modPow (x*x%modVal) (n/2L)
    | Odd  as n -> (x*(modPow x (n-1L))) % modVal

let x,N = let t = read() in t.[0],t.[1]
let a   = read()

a
|> Array.fold(fun acc a -> (acc + (modPow x a))%modVal) 0L
|> printfn "%i"
0