結果

問題 No.1063 ルートの計算 / Sqrt Calculation
ユーザー maimai8maimai8
提出日時 2020-08-05 17:34:30
言語 OCaml
(5.1.0)
結果
WA  
実行時間 -
コード長 850 bytes
コンパイル時間 282 ms
コンパイル使用メモリ 21,448 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 09:08:39
合計ジャッジ時間 3,030 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 WA -
testcase_04 AC 2 ms
5,376 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 922 ms
5,376 KB
testcase_08 AC 11 ms
5,376 KB
testcase_09 AC 1,118 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 17 ms
5,376 KB
testcase_14 AC 19 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

let () =
  let rec primes (n : int) (m : int) (k : int) (lst : int list) =
    if n < m then lst
    else if n mod m = 0 then primes (n/m) m k (m :: lst)
    else if m = 2 then primes n (m+1) k lst else primes n (m+2) k lst in
  let rec insert x lst = match lst with
    | [] -> [(1, x)]
    | (cnt, num) :: t -> if num = x then (cnt+1, num) :: t else (cnt,num) :: insert x t in
  let rec expN num cnt =
    if cnt = 0 then 1 else num * expN num (cnt-1) in
  Scanf.scanf "%d\n" @@ fun n ->
  let lst = primes n 2 n [] in
  let slst = List.fold_left (fun lst x -> insert x lst) [] lst in
  let (a,b) = List.fold_left
      (fun (a, b) (cnt, num) ->
         if cnt mod 2 = 0 then (a * (expN num (cnt/2)), b)
         else if cnt = 1 then (a, b * num)
         else (a * (num * (expN num (cnt/2))), b * num)) (1,1) slst in
  Printf.printf "%d %d\n" a b
0