結果
| 問題 |
No.371 ぼく悪いプライムじゃないよ
|
| コンテスト | |
| ユーザー |
rickytheta
|
| 提出日時 | 2016-05-13 23:03:31 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,682 bytes |
| コンパイル時間 | 1,385 ms |
| コンパイル使用メモリ | 161,284 KB |
| 実行使用メモリ | 10,496 KB |
| 最終ジャッジ日時 | 2024-10-05 17:24:38 |
| 合計ジャッジ時間 | 4,618 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 21 TLE * 1 -- * 20 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:27:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
27 | scanf("%lld%lld",&L,&H);
| ~~~~~^~~~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()
#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD
ll L,H;
bool isp[125252];
vl ps;
int main(){
scanf("%lld%lld",&L,&H);
REP(i,125252)isp[i]=true;
isp[0]=isp[1]=false;
FOR(x,2,125252){
if(!isp[x])continue;
ps.push_back(x);
{
int it = x+x;
while(it<125252){
isp[it]=false;
it+=x;
}
}
}
ll ans = 1;
ll mxmn = 1;
REP(i,ps.size()){
ll x = ps[ps.size()-1-i];
if(x<mxmn)break;
ll ub = H/x;
{
int id = upper_bound(ALL(ps),ub)-ps.begin();
if(id>0){
ll p = ps[id-1];
if(p*x>=L){
ll fct = min(p,x);
if(fct>mxmn || (fct==mxmn&&p*x>ans)){
ans = p*x;
mxmn = fct;
continue;
}
}
}
}
while(ub*x>=L && ub>1){
ll mfct=x;
if(ub<125252 && isp[ub]){
mfct = min(mfct,ub);
}else{
REP(j,ps.size()){
if(ub%ps[j]==0){
mfct=min(mfct,ps[j]);
break;
}
}
}
if(mfct>mxmn || (mfct==mxmn&&ub*x>ans)){
ans = ub*x;
mxmn = mfct;
if(mfct==x)break;
}
--ub;
}
}
printf("%lld\n",ans);
return 0;
}
rickytheta