結果
| 問題 |
No.16 累乗の加算
|
| コンテスト | |
| ユーザー |
r6eve
|
| 提出日時 | 2017-08-22 11:26:27 |
| 言語 | OCaml (5.2.1) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 774 bytes |
| コンパイル時間 | 385 ms |
| コンパイル使用メモリ | 21,248 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-09 00:28:37 |
| 合計ジャッジ時間 | 1,251 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 14 |
ソースコード
module IO = struct
(* @since 4.04.0 *)
let split_on_char sep s =
let open String in
let r = ref [] in
let j = ref (length s) in
for i = length s - 1 downto 0 do
if get s i = sep then begin
r := sub s (i + 1) (!j - i - 1) :: !r;
j := i
end
done;
sub s 0 !j :: !r
let read_ss () = read_line () |> split_on_char ' '
let read_ns () = read_ss () |> List.map int_of_string
end
let m = 1000003
let pow x n =
let rec doit x n acc =
if n = 0 then acc
else doit (x * x mod m) (n / 2) (if n mod 2 = 0 then acc else acc * x mod m) in
doit x n 1
let () =
match IO.read_ns () with
| [x; _] -> IO.read_ns () |> List.fold_left (fun s e -> (s + pow x e) mod m) 0 |> Printf.printf "%d\n"
| _ -> assert false
r6eve