結果

問題 No.3127 Multiple of Twin Prime
ユーザー norioc
提出日時 2025-04-26 03:52:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,171 ms / 2,500 ms
コード長 633 bytes
コンパイル時間 384 ms
コンパイル使用メモリ 82,272 KB
実行使用メモリ 181,188 KB
最終ジャッジ日時 2025-04-26 03:52:51
合計ジャッジ時間 16,372 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import isqrt
from itertools import pairwise
from bisect import bisect_right


def make_primes(n: int) -> list[int]:
    ps = [2]
    t = [True] * (n + 1)
    for i in range(3, n+1, 2):
        if t[i]:
            ps.append(i)
            for j in range(i+i, n+1, i):
                t[j] = False
    return ps


primes = make_primes(isqrt(10 ** 14))
twins = []
for a, b in pairwise(primes):
    if a+2 == b:
        twins.append(a * b)


def solve():
    N = int(input())
    p = bisect_right(twins, N)
    if p == 0: return -1

    return twins[p-1]


T = int(input())
for _ in range(T):
    ans = solve()
    print(ans)
0