結果

問題 No.1140 EXPotentiaLLL!
ユーザー qumazakiqumazaki
提出日時 2020-09-08 17:38:30
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 740 ms / 2,000 ms
コード長 874 bytes
コンパイル時間 507 ms
コンパイル使用メモリ 86,832 KB
実行使用メモリ 298,084 KB
最終ジャッジ日時 2023-08-20 02:01:38
合計ジャッジ時間 8,830 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 740 ms
260,672 KB
testcase_01 AC 458 ms
259,948 KB
testcase_02 AC 407 ms
261,676 KB
testcase_03 AC 369 ms
249,440 KB
testcase_04 AC 349 ms
265,280 KB
testcase_05 AC 490 ms
262,272 KB
testcase_06 AC 415 ms
258,124 KB
testcase_07 AC 493 ms
298,084 KB
testcase_08 AC 254 ms
163,024 KB
testcase_09 AC 197 ms
163,260 KB
testcase_10 AC 202 ms
163,340 KB
testcase_11 AC 205 ms
163,356 KB
testcase_12 AC 210 ms
163,344 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def sieve(n):
    if( n <= 1):
        return []
    elif(n==2):
        return [2]

    primes = [2]
    len_list = (n+1)//2
    len_sqrt = int(len_list**0.5) + 1
    flags = [True] * len_list
    flags[0] = False
    for i in range(len_sqrt):
        if(flags[i]):
            start = ((i*2+1)**2)//2
            for j in range( start, len_list, i*2+1):
                flags[j] = False
    return [2] + [i*2+1 for i in range(len_list) if flags[i]]

t = int(readline())
data = list(map(int,read().split()))

primes = sieve(5*10**6)
nums = [-1]*(5*10**6+1)
for pi in primes:
    nums[pi]=1

ans = []
it = iter(data)
for a,p in zip(it,it):
    if(nums[p]==-1):
        ans.append(-1)
    else:
        ans.append(1*(a%p > 0))

print('\n'.join(map(str,ans)))
0