結果

問題 No.1140 EXPotentiaLLL!
ユーザー titiatitia
提出日時 2020-07-31 21:45:25
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 627 ms / 2,000 ms
コード長 705 bytes
コンパイル時間 254 ms
コンパイル使用メモリ 87,084 KB
実行使用メモリ 196,036 KB
最終ジャッジ日時 2023-09-20 22:42:26
合計ジャッジ時間 8,421 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 547 ms
195,924 KB
testcase_01 AC 529 ms
195,984 KB
testcase_02 AC 533 ms
195,580 KB
testcase_03 AC 521 ms
195,704 KB
testcase_04 AC 463 ms
195,912 KB
testcase_05 AC 548 ms
196,012 KB
testcase_06 AC 541 ms
196,036 KB
testcase_07 AC 627 ms
195,916 KB
testcase_08 AC 309 ms
195,156 KB
testcase_09 AC 305 ms
194,828 KB
testcase_10 AC 299 ms
194,980 KB
testcase_11 AC 306 ms
194,828 KB
testcase_12 AC 299 ms
195,100 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

def calc(A,P):
    ANS=1
    for i in range(1,P+1):
        ANS*=i
    return pow(A,ANS,P)

import math
x=5*10**6+10
L=math.floor(math.sqrt(x)) # 平方根を求める

Primelist=[i for i in range(x+1)]
Primelist[1]=0 # 1は素数でないので0にする.
 
for i in Primelist:
    if i>L:
        break
    if i==0:
        continue
    for j in range(2*i,x+1,i):
        Primelist[j]=0

Primes=[Primelist[j] for j in range(x+1) if Primelist[j]!=0]
S=set(Primes)

T=int(input())
for tests in range(T):
    A,P=map(int,input().split())

    if P in S:
        if A%P==0:
            print(0)
        else:
            print(1)
    else:
        print(-1)
    
    
0