結果

問題 No.36 素数が嫌い!
ユーザー zimphazimpha
提出日時 2017-12-13 22:34:26
言語 PyPy3
(7.3.13)
結果
TLE  
実行時間 -
コード長 694 bytes
コンパイル時間 1,580 ms
コンパイル使用メモリ 86,876 KB
実行使用メモリ 79,540 KB
最終ジャッジ日時 2023-08-21 02:23:35
合計ジャッジ時間 8,187 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

def is_prime(n):
  if n <= 1: return False
  if n <= 3: return True
  if n % 2 == 0: return False
  u = [2, 3, 5, 7, 325, 9375, 28178, 450775, 9780504, 1795265022]
  e, c = n - 1, 0
  while e % 2 == 0:
    e >>= 1
    c += 1
  for p in u:
    if n <= p: return True
    a = pow(p, e, n)
    if a == 1:
      continue
    j = 1
    while a != n - 1:
      if j == c: return False
      a = a * a % n
      j += 1
  return True

def valid(n):
  if n == 1 or is_prime(n):
    return False
  i = 2
  while i ** 3 <= n:
    if n % i == 0:
      n //= i
      if n == 1 or is_prime(n):
        return False
      else:
        return True
  return False

print('YES' if valid(int(input())) else 'NO')
0