結果
問題 | No.1140 EXPotentiaLLL! |
ユーザー |
|
提出日時 | 2021-11-21 16:37:06 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,414 bytes |
コンパイル時間 | 231 ms |
コンパイル使用メモリ | 82,600 KB |
実行使用メモリ | 169,756 KB |
最終ジャッジ日時 | 2024-06-22 23:07:53 |
合計ジャッジ時間 | 18,848 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1,612 ms
168,900 KB |
testcase_01 | AC | 1,638 ms
168,960 KB |
testcase_02 | WA | - |
testcase_03 | AC | 1,408 ms
168,904 KB |
testcase_04 | AC | 1,222 ms
168,960 KB |
testcase_05 | AC | 1,602 ms
168,896 KB |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | AC | 549 ms
169,216 KB |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | AC | 542 ms
168,908 KB |
ソースコード
#!/usr/bin/env python3 import sys 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, N + 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(input()) er = Eratosthenes(5 * 10 ** 6 + 1) for _ in range(T): A, P = map(int, input().split()) if er.isPrime[P]: if A == P: print(0) else: print(1) else: print(-1) return if __name__ == '__main__': main()