結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
13,756 KB
testcase_01 AC 6 ms
6,944 KB
testcase_02 AC 16 ms
6,944 KB
testcase_03 AC 8 ms
6,940 KB
testcase_04 AC 3 ms
6,940 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 6 ms
6,940 KB
testcase_09 AC 26 ms
6,940 KB
testcase_10 AC 17 ms
6,940 KB
testcase_11 AC 25 ms
6,940 KB
testcase_12 AC 25 ms
6,940 KB
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 TLE -
testcase_17 AC 6 ms
6,940 KB
testcase_18 AC 4 ms
6,940 KB
testcase_19 AC 6 ms
6,940 KB
testcase_20 TLE -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
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>
using namespace std;

typedef long long int64;

vector< int > get_prime(int n)
{
  vector< bool > prime( n + 1, true);
  
  if(n >= 0) prime[0] = false;
  if(n >= 1) prime[1] = false;
  
  for(int i = 2; i * i <= n; i++){
    if(prime[i]){
      for(int j = i + i; j <= n; j += i) prime[j] = false;
    }
  }
  vector< int > primes;
  for(int i = 2; i <= n; i++) {
    if(prime[i]) primes.push_back(i);
  }
  return(primes);
}

int64 L, H;
int64 rec(int64 idx, int64 weight, vector< int >& prime, bool first = false)
{
  if(idx >= prime.size() || weight > H) return(2);
  return(max((!first && L <= weight && weight <= H) ? weight : 2LL, max(rec(idx, weight * prime[idx], prime), rec(idx + 1, weight, prime, first))));
}
int main()
{
  vector< int > prime = get_prime(100000);
  cin >> L >> H;
  pair< int64, int64 > ret(2, 2);
  for(int i = 0; i < prime.size(); i++)  {
    int val = rec(i, prime[i], prime, true);
    if(val != 2) ret = max(ret, {prime[i], val});
  }
  cout << ret.second << endl;
}
0