結果

問題 No.7 プライムナンバーゲーム
ユーザー irisAshirisAsh
提出日時 2017-08-15 14:28:01
言語 JavaScript
(node v21.7.1)
結果
AC  
実行時間 418 ms / 5,000 ms
コード長 524 bytes
コンパイル時間 195 ms
コンパイル使用メモリ 6,820 KB
実行使用メモリ 48,776 KB
最終ジャッジ日時 2024-04-09 04:22:09
合計ジャッジ時間 5,064 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
39,168 KB
testcase_01 AC 61 ms
39,040 KB
testcase_02 AC 418 ms
48,748 KB
testcase_03 AC 96 ms
45,600 KB
testcase_04 AC 80 ms
45,696 KB
testcase_05 AC 79 ms
45,440 KB
testcase_06 AC 162 ms
46,152 KB
testcase_07 AC 136 ms
45,628 KB
testcase_08 AC 101 ms
45,824 KB
testcase_09 AC 203 ms
46,312 KB
testcase_10 AC 59 ms
39,168 KB
testcase_11 AC 134 ms
45,644 KB
testcase_12 AC 288 ms
48,500 KB
testcase_13 AC 309 ms
48,772 KB
testcase_14 AC 370 ms
48,776 KB
testcase_15 AC 364 ms
48,748 KB
testcase_16 AC 333 ms
48,716 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

let i = require('fs').readFileSync('/dev/stdin', 'utf8').split('\n')[0]
let p = Array.from(new Array(i - 1)).map((e,i) => i+2)
let t = []
for (let c = 0; p[c] <= Math.sqrt(i);) {
  t.push(p[c])
  p = p.filter((e) => e % p[c] != 0)
}
p = t.concat(p)
let a = Array.from(new Array(i + 1)).fill(void 0)
a[0] = a[1] = true
const f = (n) => {
  let r = true
  for (let e of p) {
    if (e > n) break
    if (a[n - e] === void 0) r &= f(n - e)
    else r &= a[n - e]
  }
  a[n] = !r
  return !r
}
console.log(f(i) ? 'Win' : 'Lose')
0