結果

問題 No.1140 EXPotentiaLLL!
ユーザー MineMine
提出日時 2021-01-28 18:06:31
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,915 ms / 2,000 ms
コード長 975 bytes
コンパイル時間 631 ms
コンパイル使用メモリ 87,012 KB
実行使用メモリ 119,060 KB
最終ジャッジ日時 2023-09-08 09:17:25
合計ジャッジ時間 20,566 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,750 ms
117,400 KB
testcase_01 AC 1,915 ms
118,716 KB
testcase_02 AC 1,607 ms
117,804 KB
testcase_03 AC 1,595 ms
118,972 KB
testcase_04 AC 1,309 ms
118,768 KB
testcase_05 AC 1,856 ms
119,060 KB
testcase_06 AC 1,774 ms
118,684 KB
testcase_07 AC 1,871 ms
117,724 KB
testcase_08 AC 395 ms
116,516 KB
testcase_09 AC 392 ms
116,544 KB
testcase_10 AC 396 ms
116,392 KB
testcase_11 AC 397 ms
116,304 KB
testcase_12 AC 409 ms
116,168 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
import math

def Sieve_of_Eratosthenes(maxA):
    lst = [-1]*(maxA+1)
    lst[0] = 0
    lst[1] = 1
    for i in range(2, maxA+1):
        if lst[i] == -1:
            for g in range(i, maxA+1, i):
                if lst[g] == -1:
                    lst[g] = i
    return lst

def is_prime(n):
    d = defaultdict(int)
    now = n
    while True:
        if now == lst[now]:
            if now != 1:
                d[now] += 1
            break
        r = lst[now]
        while now % r == 0:
            now //= r
            d[r] += 1
        if d[r] > 1 or len(d) > 1:
            return False
    if len(d) == 1:
        return True
    else:
        return False

maxA = 5*10**6 + 1
lst = Sieve_of_Eratosthenes(maxA)

t = int(input())
for _ in range(t):
    a, p = map(int, input().split())
    if is_prime(p):
        if math.gcd(a, p) == 1:
            print(1)
        else:
            print(0)
    else:
        print(-1)
    
0