結果

問題 No.371 ぼく悪いプライムじゃないよ
ユーザー rickythetarickytheta
提出日時 2016-05-14 00:04:17
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,613 bytes
コンパイル時間 1,391 ms
コンパイル使用メモリ 167,448 KB
実行使用メモリ 122,656 KB
最終ジャッジ日時 2024-04-15 17:33:43
合計ジャッジ時間 4,226 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,756 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 3 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 3 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 2 ms
6,944 KB
testcase_17 AC 3 ms
6,944 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 2 ms
6,944 KB
testcase_20 AC 4 ms
6,940 KB
testcase_21 AC 9 ms
6,944 KB
testcase_22 AC 4 ms
6,940 KB
testcase_23 AC 8 ms
6,940 KB
testcase_24 TLE -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
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<10000){
    // 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{
    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