結果

問題 No.3127 Multiple of Twin Prime
ユーザー detteiuu
提出日時 2025-04-25 21:38:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 859 ms / 2,500 ms
コード長 645 bytes
コンパイル時間 213 ms
コンパイル使用メモリ 81,968 KB
実行使用メモリ 204,904 KB
最終ジャッジ日時 2025-04-25 21:38:24
合計ジャッジ時間 11,691 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

from bisect import bisect_left, bisect_right

def eratosthenes(n):
    sieve = [True] * (n + 1)
    for i in range(int(n**0.5) + 1):
        if i < 2:
            sieve[i] = False
        elif sieve[i]:
            for j in range(2, n//i + 1):
                sieve[i * j] = False
    ans = []
    for i in range(n+1):
        if sieve[i]:
            ans.append(i)
    return ans

E = eratosthenes(10**7)
A = []
for i in range(len(E)-1):
    l, r = E[i], E[i+1]
    if l+2 == r:
        A.append(l*r)

for _ in range(int(input())):
    N = int(input())
    b = bisect_right(A, N)
    if 1 <= b:
        print(A[b-1])
    else:
        print(-1)
0