結果

問題 No.1140 EXPotentiaLLL!
ユーザー marroncastlemarroncastle
提出日時 2020-07-31 21:32:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 639 ms / 2,000 ms
コード長 521 bytes
コンパイル時間 260 ms
コンパイル使用メモリ 87,124 KB
実行使用メモリ 140,016 KB
最終ジャッジ日時 2023-09-20 21:51:45
合計ジャッジ時間 9,228 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 610 ms
131,700 KB
testcase_01 AC 575 ms
131,708 KB
testcase_02 AC 584 ms
140,016 KB
testcase_03 AC 545 ms
129,740 KB
testcase_04 AC 511 ms
126,520 KB
testcase_05 AC 569 ms
132,448 KB
testcase_06 AC 582 ms
131,728 KB
testcase_07 AC 639 ms
136,208 KB
testcase_08 AC 348 ms
115,276 KB
testcase_09 AC 373 ms
115,468 KB
testcase_10 AC 352 ms
115,276 KB
testcase_11 AC 349 ms
115,380 KB
testcase_12 AC 339 ms
115,244 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
def sieve(n):
  is_prime = [True for _ in range(n+1)]
  is_prime[0] = False
  for i in range(2, n+1):
    if is_prime[i-1]:
      j = 2 * i
      while j <= n:
        is_prime[j-1] = False
        j += i
  return is_prime
def solve():
  input = sys.stdin.readline
  is_prime = sieve(5*10**6)
  T = int(input())
  ans = [-1]*T
  for i in range(T):
    A,P = map(int, input().split())
    if is_prime[P-1]:
      if A%P==0:
        ans[i] = 0
      else:
        ans[i] = 1
  return ans
print(*solve(),sep='\n')
0