結果

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

ソースコード

diff #

P=[]
def sieve_of_eratosthenes(n):
  prime = [True for i in range(n+1)]
  p = 2
  while (p * p <= n):
    if (prime[p] == True):
      for i in range(p * 2, n+1, p):
        prime[i] = False
    p += 1
  for p in range(2, n):
    if prime[p]:
      P.append(p)
sieve_of_eratosthenes(10**7)
L=[]
for i in range(len(P)-1):
	if P[i]+2==P[i+1]:
		L.append(P[i]*P[i+1])

import bisect
t=int(input())
for _ in range(t):
	n=int(input())
	if n<15:
		print(-1)
	else:
		id=bisect.bisect_right(L,n)
		print(L[id-1])
0