結果

問題 No.1140 EXPotentiaLLL!
ユーザー mkawa2mkawa2
提出日時 2021-06-28 11:15:30
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 466 ms / 2,000 ms
コード長 1,487 bytes
コンパイル時間 366 ms
コンパイル使用メモリ 87,176 KB
実行使用メモリ 142,468 KB
最終ジャッジ日時 2023-09-07 18:20:02
合計ジャッジ時間 7,077 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 439 ms
142,172 KB
testcase_01 AC 429 ms
142,100 KB
testcase_02 AC 420 ms
142,468 KB
testcase_03 AC 402 ms
141,932 KB
testcase_04 AC 361 ms
142,100 KB
testcase_05 AC 443 ms
142,132 KB
testcase_06 AC 437 ms
142,372 KB
testcase_07 AC 466 ms
141,960 KB
testcase_08 AC 205 ms
141,164 KB
testcase_09 AC 210 ms
141,136 KB
testcase_10 AC 212 ms
141,384 KB
testcase_11 AC 206 ms
141,212 KB
testcase_12 AC 207 ms
141,020 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.buffer.readline())
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def LI1(): return list(map(int1, sys.stdin.buffer.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def BI(): return sys.stdin.buffer.readline().rstrip()
def SI(): return sys.stdin.buffer.readline().rstrip().decode()
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = 10**16
md = 998244353
# md = 10**9+7

class Sieve:
    def __init__(self, n):
        self.plist = [2]  # n以下の素数のリスト
        min_prime_factor = [2, 0] * (n // 2 + 5)
        for x in range(3, n + 1, 2):
            if min_prime_factor[x] == 0:
                min_prime_factor[x] = x
                self.plist.append(x)
                if x ** 2 > n: continue
                for y in range(x ** 2, n + 5, 2 * x):
                    if min_prime_factor[y] == 0:
                        min_prime_factor[y] = x
        self.min_prime_factor = min_prime_factor

    def isprime(self, x):
        return self.min_prime_factor[x] == x

def solve():
    a,p=LI()
    if sv.isprime(p):
        if a%p:print(1)
        else:print(0)
    else:print(-1)

sv=Sieve(5000001)
for _ in range(II()):
    solve()
0