結果

問題 No.211 素数サイコロと合成数サイコロ (1)
ユーザー r6eve
提出日時 2017-08-11 10:46:20
言語 OCaml
(5.2.1)
結果
WA  
実行時間 -
コード長 589 bytes
コンパイル時間 205 ms
コンパイル使用メモリ 19,692 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-09 00:12:22
合計ジャッジ時間 1,114 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 7 WA * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

let pow x n m =
  let rec doit x n acc =
    if n = 0 then acc
    else if n mod 2 = 0 then doit (x * x mod m) (n / 2) acc
    else doit (x * x mod m) (n / 2) (acc * x mod m) in
  doit x n 1

let pow x n m =
  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 prime_p n =
  if n == 2 then true
  else if n < 2 || n mod 2 = 0 then false
  else if pow 2 (n - 1) n = 1 then true
  else false

let () =
  let k = read_int () in
  print_endline (if prime_p k then "0" else "0.0277777777777777778")
0