結果

問題 No.371 ぼく悪いプライムじゃないよ
ユーザー togatogatogatoga
提出日時 2016-05-14 00:12:49
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 2,180 bytes
コンパイル時間 1,625 ms
コンパイル使用メモリ 170,692 KB
実行使用メモリ 13,760 KB
最終ジャッジ日時 2024-04-15 17:44:44
合計ジャッジ時間 5,129 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
13,760 KB
testcase_01 AC 3 ms
6,940 KB
testcase_02 AC 6 ms
6,940 KB
testcase_03 AC 4 ms
6,940 KB
testcase_04 AC 3 ms
6,944 KB
testcase_05 AC 3 ms
6,944 KB
testcase_06 AC 3 ms
6,940 KB
testcase_07 AC 4 ms
6,940 KB
testcase_08 AC 3 ms
6,944 KB
testcase_09 AC 4 ms
6,940 KB
testcase_10 AC 4 ms
6,940 KB
testcase_11 AC 4 ms
6,944 KB
testcase_12 AC 4 ms
6,944 KB
testcase_13 AC 32 ms
6,940 KB
testcase_14 AC 31 ms
6,944 KB
testcase_15 AC 31 ms
6,940 KB
testcase_16 AC 293 ms
6,944 KB
testcase_17 AC 4 ms
6,940 KB
testcase_18 AC 4 ms
6,944 KB
testcase_19 AC 3 ms
6,944 KB
testcase_20 AC 71 ms
6,944 KB
testcase_21 AC 71 ms
6,940 KB
testcase_22 AC 57 ms
6,944 KB
testcase_23 AC 109 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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define mp       make_pair
#define mt	 make_tuple
#define pb       push_back
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    pair<int,int>      pii;
typedef    pair<long,long>    pll;

const int INF=1<<29;
const double EPS=1e-9;
const int MOD = 100000007;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
const int MAX_N = 100002;
bool is_prime[MAX_N];
vector<int> primes;
void gen_prime(){
  memset(is_prime, true, sizeof(is_prime));
  is_prime[0] = false;
  is_prime[1] = false;
  for (int i = 2; i < MAX_N; i++){
    if (not is_prime[i])continue;
    primes.push_back(i);
    for (int j = i + i; j < MAX_N; j += i){
      is_prime[j] = false;
    }
  }
  return ;
}
#ifdef _MSC_VER
#include <Windows.h>
double get_ms() { return (double)GetTickCount64() / 1000; }
#else
#include <sys/time.h>
double get_ms() { struct timeval t; gettimeofday(&t, NULL); return (double)t.tv_sec * 1000 + (double)t.tv_usec / 1000; }
#endif

class Timer
{
private:
  double start_time;
  double elapsed;

#ifdef USE_RDTSC
  double get_sec() { return get_absolute_sec(); }
#else
  double get_sec() { return get_ms() / 1000; }
#endif

public:
  Timer() {}

  void start() { start_time = get_sec(); }
  double get_elapsed() { return elapsed = get_sec() - start_time; }
};
ll L,H;
unordered_set<ll> flag;
Timer timer;
ll max_value;
void get_max_value(ll val, int index){
  if (timer.get_elapsed() > 3)return ;
  if (val > H)return ;
  if (flag.size() > 0 and L <= val and val <= H){
    //    cout << val << endl;
    max_value = max(max_value, val);
  }
  flag.insert(val);
  for (int i = index; i < primes.size(); i++){
    if (val * primes[i] <= H){
      if (flag.count(val * primes[i]) > 0)continue;
      get_max_value(val * primes[i], index);
    }
  }
}

ll result;
int main(){
  cin >> L >>H;
  gen_prime();
  result = 0;
  sort(primes.begin(), primes.end());

  for (int i = primes.size() - 1; i >=0; i--){
    flag.clear();
    max_value = 0;
    timer.start();
    get_max_value(primes[i], i);
    if (max_value != 0){
      break;
    }

  }

  cout << max_value << endl;
}
0