結果

問題 No.1140 EXPotentiaLLL!
ユーザー tktk_snsn
提出日時 2020-12-23 21:06:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 558 ms / 2,000 ms
コード長 676 bytes
コンパイル時間 686 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 135,736 KB
最終ジャッジ日時 2024-09-21 16:32:16
合計ジャッジ時間 7,449 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
U = 5 * 10 ** 6


def prime_sieve(N):
    #sieve[i] : iの最小の素因数
    sieve = [0] * (N + 1)
    prime = []
    for i in range(2, N + 1):
        if sieve[i] == 0:
            sieve[i] = i
            prime.append(i)
        for p in prime:
            if p > sieve[i] or i * p > N:
                break
            sieve[i * p] = p
    return sieve


sieve = prime_sieve(U)


T = int(input())
for _ in range(T):
    a, p = map(int, input().split())
    if p == 1 or sieve[p] != p:
        print(-1)
    elif gcd(a, p) == 1:
        print(1)
    else:
        print(0)
0