結果
問題 | No.3127 Multiple of Twin Prime |
ユーザー |
![]() |
提出日時 | 2025-04-25 21:33:38 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 138 ms / 2,500 ms |
コード長 | 1,208 bytes |
コンパイル時間 | 3,340 ms |
コンパイル使用メモリ | 277,688 KB |
実行使用メモリ | 13,576 KB |
最終ジャッジ日時 | 2025-04-25 21:33:48 |
合計ジャッジ時間 | 6,237 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 12 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll=long long; using ull=unsigned long long; using pll=pair<ll,ll>; using tll=tuple<ll,ll,ll>; using ld=long double; constexpr ll INF=(1ll<<60); #define rep(i,n) for (ll i=0;i<(ll)(n);i++) #define replr(i,l,r) for (ll i=(ll)(l);i<(ll)(r);i++) #define all(v) v.begin(),v.end() #define len(v) ((ll)v.size()) template<class T> inline bool chmin(T &a,T b){ if(a>b){ a=b; return true; } return false; } template<class T> inline bool chmax(T &a,T b){ if(a<b){ a=b; return true; } return false; } constexpr int N=(ll)1e7+1; bool np[N]; vector<ll> v; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); np[0]=np[1]=true; for(int i=2;i<N;i++){ if(np[i]) continue; for(int j=i+i;j<N;j+=i){ np[j]=true; } } for(int i=2;i+2<N;i++){ if(!np[i]&&!np[i+2]) v.push_back((ll)i*(i+2)); } ll t; cin >> t; while(t--){ ll n; cin >> n; auto itr=upper_bound(all(v),n); if(itr==v.begin()){ cout << "-1\n"; }else{ itr--; cout << *itr << '\n'; } } }