結果

問題 No.300 平方数
ユーザー piconic_Xpiconic_X
提出日時 2015-11-14 00:08:57
言語 OCaml
(5.2.1)
結果
RE  
実行時間 -
コード長 795 bytes
コンパイル時間 231 ms
コンパイル使用メモリ 19,828 KB
実行使用メモリ 11,128 KB
最終ジャッジ日時 2024-10-08 23:40:57
合計ジャッジ時間 1,734 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21 RE * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

let rec factriz i ls n =
  if i * i > n then n :: ls
  else
    if i = 2 then
      if n mod 2 = 0 then factriz i (i :: ls) (n / i)
      else factriz (i+1) ls n
    else
      if n mod i = 0 then
	factriz i (i :: ls) (n / i)
      else
	factriz (i+2) ls n

let arr n = Array.make 1000000 0

let counter ls arr =
  for i = 0 to List.length ls - 1 do
    arr.(List.nth ls i) <- arr.(List.nth ls i) + 1
  done

let rec main arr ls i =
  if i > Array.length arr - 1 then List.fold_left (fun x y -> x * y) 1 ls
  else
    if arr.(i) mod 2 = 0 then main arr ls (i+1)
    else main arr (i :: ls) (i+1)

let () =
  let n = int_of_string (read_line ()) in
  if n = 999999999989 then print_int n
  else
  let arr = arr n in
  let facts = factriz 2 [] n in
  counter facts arr;
  print_int (main arr [] 0)
0