結果

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

ソースコード

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 rec matchls n = function
    [] ->true
   |hd :: tl -> if n <> hd then matchls n tl
	     else false

let rec main ls ls1 =
  match ls with
    [] -> List.fold_left (fun x y -> x * y) 1 ls1
   |hd :: tl -> if matchls hd ls1 = false then main tl (List.filter ((fun x y -> x <> y) hd) ls1)
		else main tl (hd :: ls1)

let () =
  let n = int_of_string (read_line ()) in
  print_int (main (factriz 2 [] n) [])
0