結果

問題 No.3127 Multiple of Twin Prime
ユーザー hato336
提出日時 2025-04-25 22:26:52
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,042 bytes
コンパイル時間 233 ms
コンパイル使用メモリ 82,504 KB
実行使用メモリ 94,692 KB
最終ジャッジ日時 2025-04-25 22:27:01
合計ジャッジ時間 7,935 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample TLE * 1
other -- * 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
input = sys.stdin.readline
a = []
for i in range(2,10000000+100):
    if MillerRabin_64bit(i) == MillerRabin_64bit(i+2) == True:
        a.append(i*(i+2))
a = list(set(a))
a.sort()
print(a)
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