結果

問題 No.3127 Multiple of Twin Prime
ユーザー hato336
提出日時 2025-04-25 22:30:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 924 ms / 2,500 ms
コード長 1,276 bytes
コンパイル時間 436 ms
コンパイル使用メモリ 82,592 KB
実行使用メモリ 232,392 KB
最終ジャッジ日時 2025-04-25 22:30:57
合計ジャッジ時間 14,054 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys,collections,bisect
def MillerRabin_64bit(x):
    if x <= 1:
        return False
    if x == 2:
        return True
    if x % 2 == 0:
        return False
    if x < 1 << 30:
        test = [2, 7, 61]
    else:
        test = [2,325,9375,28178,450775,9780504,1795265022]
    s = 0
    d = x - 1
    while d & 1 == 0:
        s += 1
        d >>= 1
    for i in test:
        if x <= i:
            return True
        y = pow(i,d,x)
        if y == 1 or y == x - 1:
            continue
        c = 0
        for j in range(s-1):
            y = y * y % x
            if y == x - 1:
                c = 1
                break
        if not c:
            return False
    return True
def eratosthenes(n):
    is_prime = [False, False] + [True] * (n-1)
    for p in range(2, n+1):
        if not(is_prime[p]):
            continue
        for k in range(p*2, n+1, p):
            is_prime[k] = False
    return is_prime

input = sys.stdin.readline
b = eratosthenes(10**7+10)
a = []
for i in range(2,len(b)):
    if i+2 < len(b) and b[i] == b[i+2] == True:
        a.append(i*(i+2))
a = list(set(a))
a.sort()

t = int(input())
for i in range(t):
    x = int(input())
    y = bisect.bisect_right(a,x)
    if y == 0:
        print(-1)
    else:
        print(a[y-1])
0