結果

問題 No.3127 Multiple of Twin Prime
ユーザー ooaiu
提出日時 2025-05-10 10:05:10
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 430 ms / 2,500 ms
コード長 510 bytes
コンパイル時間 3,679 ms
コンパイル使用メモリ 279,436 KB
実行使用メモリ 42,980 KB
最終ジャッジ日時 2025-05-10 10:05:21
合計ジャッジ時間 11,155 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb emplace_back
#define N 10000007
int lpf[N];
void init()
{
	for(int i=2;i<N;i++)if(lpf[i]==0)for(int j=i;j<N;j+=i)if(lpf[j]==0)lpf[j]=i;
}
ll t,n;
int main()
{
	init();
	cin>>t;
	vector<ll> A;
	for(int x=3;x<N-2;x++)if(lpf[x]==x&&lpf[x+2]==x+2)A.pb((ll)x*(x+2));
	sort(A.begin(),A.end());
	for(;t--;)
	{
		cin>>n;
		if(n<15)
		{
			cout<<-1<<"\n";
			continue;
		}
		cout<<A[upper_bound(A.begin(),A.end(),n)-A.begin()-1]<<"\n";
	}
}
0