結果

問題 No.211 素数サイコロと合成数サイコロ (1)
コンテスト
ユーザー r6eve
提出日時 2017-08-11 10:46:20
言語 OCaml
(5.4.1)
コンパイル:
ocamlfind ocamlopt -linkpkg -package zarith,str _filename_ -o a.out
実行:
./a.out
結果
WA  
実行時間 -
コード長 589 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 217 ms
コンパイル使用メモリ 20,832 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-04-25 04:28:59
合計ジャッジ時間 2,953 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 7 WA * 26
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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