結果

問題 No.371 ぼく悪いプライムじゃないよ
ユーザー どららどらら
提出日時 2016-05-14 00:41:12
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,364 bytes
コンパイル時間 765 ms
コンパイル使用メモリ 84,008 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-04-15 18:32:14
合計ジャッジ時間 4,059 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,752 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 4 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 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 16 ms
5,376 KB
testcase_14 AC 15 ms
5,376 KB
testcase_15 AC 18 ms
5,376 KB
testcase_16 AC 230 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 17 ms
5,376 KB
testcase_21 AC 13 ms
5,376 KB
testcase_22 AC 5 ms
5,376 KB
testcase_23 AC 26 ms
5,376 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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <iostream>
#include <queue>
#include <list>
#include <stack>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;

#define MAX_PRIME 20000
bool isprime[MAX_PRIME+1]; 
vector<int> primes; 
void init_prime(){
  fill(isprime, isprime+MAX_PRIME+1, true); 
  isprime[0] = isprime[1] = false; 
  for(int i = 2; i <= MAX_PRIME; i++) { 
    if (isprime[i]) { 
      primes.push_back(i); 
      for(int j = i*2; j <= MAX_PRIME; j += i) 
      isprime[j] = false; 
    } 
  } 
}

ll ret;
void dfs(int i, ll now, ll L, ll H){
  if(i>=primes.size()) return;
  ll p = primes[i];
  ll q = 1;
  while(now*q<=H){
    if(L<=now*q){
      ret = max(ret, now*q);
    }
    dfs(i+1, now*q, L, H);
    q *= p;
  }
}


int main(){
  ios::sync_with_stdio(false);
  init_prime();

  ll L, H;
  cin >> L >> H;

  for(int i=primes.size()-1; i>=0; i--){
    ret = -1;
    dfs(i,primes[i],L,H);
    if(ret > 0 && ret != primes[i]){
      cout << ret << endl;
      break;
    }
  }
  return 0;
}
0