結果

問題 No.211 素数サイコロと合成数サイコロ (1)
ユーザー r6ever6eve
提出日時 2017-08-11 10:46:20
言語 OCaml
(5.1.0)
結果
WA  
実行時間 -
コード長 589 bytes
コンパイル時間 184 ms
コンパイル使用メモリ 19,820 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-17 08:39:40
合計ジャッジ時間 1,155 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 2 ms
5,376 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

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