結果

問題 No.1140 EXPotentiaLLL!
ユーザー FromBooskaFromBooska
提出日時 2023-10-02 15:10:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,546 ms / 2,000 ms
コード長 530 bytes
コンパイル時間 337 ms
コンパイル使用メモリ 87,152 KB
実行使用メモリ 117,396 KB
最終ジャッジ日時 2023-10-02 15:11:01
合計ジャッジ時間 16,648 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,509 ms
116,704 KB
testcase_01 AC 1,507 ms
116,944 KB
testcase_02 AC 1,546 ms
117,016 KB
testcase_03 AC 1,287 ms
116,816 KB
testcase_04 AC 1,108 ms
116,784 KB
testcase_05 AC 1,468 ms
116,788 KB
testcase_06 AC 1,438 ms
117,120 KB
testcase_07 AC 1,513 ms
117,396 KB
testcase_08 AC 354 ms
116,212 KB
testcase_09 AC 340 ms
116,084 KB
testcase_10 AC 347 ms
115,844 KB
testcase_11 AC 369 ms
115,840 KB
testcase_12 AC 337 ms
116,272 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# ポラード・ロー、ミラー・ラビンでTLE
# 問題制約を見るとP<10**6となっているので最初に素数列挙しよう

n = 5*10**6+5
is_prime = [1]*(n + 1)
is_prime[0] = 0  
is_prime[1] = 0
for p in range(2, n + 1):
    if is_prime[p]:
        for q in range(2*p, n + 1, p):
            is_prime[q] = 0

T = int(input())
for t in range(T):
    A, P = map(int, input().split())
    if is_prime[P] == 0:
        print(-1)
    else:
        if A%P == 0:
            print(0)
        else:
            print(1)
0