結果

問題 No.1140 EXPotentiaLLL!
ユーザー kept1994kept1994
提出日時 2021-11-21 16:51:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 582 ms / 2,000 ms
コード長 1,484 bytes
コンパイル時間 1,906 ms
コンパイル使用メモリ 86,864 KB
実行使用メモリ 118,196 KB
最終ジャッジ日時 2023-09-05 02:29:46
合計ジャッジ時間 8,574 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 552 ms
118,092 KB
testcase_01 AC 544 ms
117,728 KB
testcase_02 AC 528 ms
118,196 KB
testcase_03 AC 509 ms
117,452 KB
testcase_04 AC 463 ms
117,136 KB
testcase_05 AC 544 ms
117,660 KB
testcase_06 AC 536 ms
117,700 KB
testcase_07 AC 582 ms
118,160 KB
testcase_08 AC 265 ms
114,812 KB
testcase_09 AC 266 ms
114,580 KB
testcase_10 AC 261 ms
114,688 KB
testcase_11 AC 262 ms
114,808 KB
testcase_12 AC 264 ms
114,820 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
import sys
from sys import stdin

class Eratosthenes():
    """ 素数列挙
    計算量 : O(NloglogN)
    """
    def __init__(self, N: int) -> None:
        self.isPrime = [True] * (N + 1) # 数iが素数かどうかのフラグ
        self.isPrime[0] = False
        self.isPrime[1] = False
        # self.minfactor = [0] * (N + 1) # 数iの最小の素因数
        # self.minfactor[1] = 1
        # self.primes = []    # 数Nまでの素数のリスト
        for p in range(2, int(N ** 0.5) + 1):  # p : 判定対象の数
            if not self.isPrime[p]:
                continue
            # self.minfactor[p] = p
            # self.primes.append(p)
            # pが素数のためそれ以降に出現するpの倍数を除外する。
            # なお、ループはp始まりでも良いが、p * _ のかける側はすでに同じ処理で弾かれているはずのため無駄。
            for i in range(p * p, N + 1, p):
                # if self.minfactor[i] == 0:
                #     self.minfactor[i] = p
                self.isPrime[i] = False
        return

def main():
    T = int(stdin.readline())
    er = Eratosthenes(5 * 10 ** 6 + 1)
    for _ in range(T):
        A, P = map(int, stdin.readline().split())
        if er.isPrime[P]:
            if A % P == 0:
                print(0)
            else:
                print(1)
        else:
            print(-1)
    return


if __name__ == '__main__':
    main()
0