結果

問題 No.371 ぼく悪いプライムじゃないよ
ユーザー rickythetarickytheta
提出日時 2016-05-14 00:05:20
言語 C++11
(gcc 11.4.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,282 bytes
コンパイル時間 1,336 ms
コンパイル使用メモリ 162,548 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2024-04-20 02:59:05
合計ジャッジ時間 11,357 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
10,624 KB
testcase_01 AC 3 ms
5,248 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 26 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 10 ms
5,376 KB
testcase_21 AC 9 ms
5,376 KB
testcase_22 AC 545 ms
5,376 KB
testcase_23 AC 8 ms
5,376 KB
testcase_24 AC 3 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 3 ms
5,376 KB
testcase_28 AC 7 ms
5,376 KB
testcase_29 AC 3 ms
5,376 KB
testcase_30 AC 206 ms
5,376 KB
testcase_31 AC 33 ms
5,376 KB
testcase_32 AC 16 ms
5,376 KB
testcase_33 AC 786 ms
5,376 KB
testcase_34 AC 616 ms
5,376 KB
testcase_35 AC 980 ms
6,944 KB
testcase_36 AC 531 ms
5,376 KB
testcase_37 AC 23 ms
5,376 KB
testcase_38 AC 546 ms
5,376 KB
testcase_39 AC 56 ms
5,376 KB
testcase_40 AC 348 ms
5,376 KB
testcase_41 TLE -
testcase_42 TLE -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:37:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   37 |   scanf("%lld%lld",&L,&H);
      |   ~~~~~^~~~~~~~~~~~~~~~~~

ソースコード

diff #

#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[100000];
vl ps;

ll pow(ll a,ll b){
  ll r = 1;
  while(b){
    if(b&1)r=r*a;
    a=a*a;
    b>>=1;
  }
  return r;
}

int main(){
  scanf("%lld%lld",&L,&H);
  REP(i,100000)isp[i]=true;
  isp[0]=isp[1]=false;
  FOR(x,2,100000){
    if(!isp[x])continue;
    ps.push_back(x);
    {
      int it = x+x;
      while(it<100000){
        isp[it]=false;
        it+=x;
      }
    }
  }
  if(H-L<100000){
    // brute-force
    ll mx = L-1;
    ll mfct = 0;
    FOR(x,L,H+1){
      REP(i,ps.size()){
        ll p = ps[i];
        if(x<=p)break;
        if(x%p==0){
          if(p>=mfct){
            mfct = p;
            mx = x;
          }
          break;
        }
      }
    }
    printf("%lld\n",mx);
  }else{
    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;
      while(ub*x>=L && ub>1){
        ll mfct=x;
        if(ub<100000 && isp[ub]){
          mfct = min(x,ub);
        }else{
          REP(j,ps.size()){
            if(ub%ps[j]==0){
              mfct=min(mfct,ps[j]);
              break;
            }
          }
        }
        ll fct = min(mfct,x);
        if(fct>mxmn || (fct==mxmn&&ub*x>ans)){
          ans = ub*x;
          mxmn = fct;
          if(fct==x)break;
        }
        --ub;
      }
    }
    printf("%lld\n",ans);
    // set<ll> dp;
    // dp.insert(1);
    // FOR(i,0,ps.size()){
    //   ll x = ps[ps.size()-1-i];
    //   ll ans = -1;
    //   for(ll p : dp){
    //     if(p*x>H)break;
    //     dp.insert(p*x);
    //     if(p!=1 && L<=p*x){
    //       ans = max(ans,p*x);
    //     }
    //   }
    //   if(ans!=-1){
    //     printf("%lld\n",ans);
    //     return 0;
    //   }
    // }
  }
  return 0;
}
0