結果
問題 |
No.3127 Multiple of Twin Prime
|
ユーザー |
|
提出日時 | 2025-04-28 19:05:18 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 111 ms / 2,500 ms |
コード長 | 748 bytes |
コンパイル時間 | 2,326 ms |
コンパイル使用メモリ | 194,520 KB |
実行使用メモリ | 45,736 KB |
最終ジャッジ日時 | 2025-04-28 19:05:28 |
合計ジャッジ時間 | 6,139 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 12 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:36:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 36 | scanf("%d",&T); | ~~~~~^~~~~~~~~ main.cpp:39:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 39 | scanf("%lld",&x); | ~~~~~^~~~~~~~~~~
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int INF=0x3f3f3f3f; const ll LLINF=0x3f3f3f3f3f3f3f3fLL; const int MAX=1e7+10; //x is a prime if prime[x]==x(x>=2) int p[MAX],tot,prime[MAX]; void init_prime(int n) { int i,j; tot=0; memset(prime,0,sizeof prime); prime[1]=1; for(i=2;i<=n;i++) { if(!prime[i]) prime[i]=p[tot++]=i; for(j=0;j<tot&&p[j]*i<=n;j++) { prime[i*p[j]]=p[j]; if(i%p[j]==0) break; } } } int main() { int T,i; ll x; init_prime(MAX-10); vector<ll> res; res.push_back(-1); for(i=1;i<tot;i++) { if(p[i-1]+2==p[i]) res.push_back(1LL*p[i-1]*p[i]); } scanf("%d",&T); while(T--) { scanf("%lld",&x); printf("%lld\n",*--upper_bound(res.begin(),res.end(),x)); } return 0; }