結果

問題 No.1063 ルートの計算 / Sqrt Calculation
ユーザー maimai8maimai8
提出日時 2020-08-05 17:35:40
言語 OCaml
(5.1.0)
結果
AC  
実行時間 1,129 ms / 2,000 ms
コード長 838 bytes
コンパイル時間 309 ms
コンパイル使用メモリ 21,576 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-17 09:08:42
合計ジャッジ時間 3,108 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 948 ms
6,940 KB
testcase_08 AC 11 ms
6,944 KB
testcase_09 AC 1,129 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 18 ms
6,944 KB
testcase_14 AC 19 ms
6,940 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 2 ms
6,940 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 * (expN num (cnt/2)), b * num)) (1,1) slst in
  Printf.printf "%d %d\n" a b
0