結果

問題 No.371 ぼく悪いプライムじゃないよ
ユーザー togari_takamoto
提出日時 2016-05-13 23:32:50
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,389 bytes
コンパイル時間 1,568 ms
コンパイル使用メモリ 166,136 KB
実行使用メモリ 13,636 KB
最終ジャッジ日時 2024-10-05 18:12:17
合計ジャッジ時間 4,335 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3 WA * 1
other AC * 8 WA * 12 TLE * 1 -- * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
 
using ll = long long; using ld = long double; using ull = unsigned long long; using uint = unsigned int;
using vi  = vector<int>; using vb  = vector<bool>; using vd  = vector<double>; using vl  = vector<ll>;
using vvi = vector<vi>;  using vvb = vector<vb>;   using vvd = vector<vd>;     using vvl = vector<vl>;
 
#define REP(i,n) for(ll i=0; i<(n); ++i)
#define FOR(i,b,n) for(ll i=(b); i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()

vb eratosthenes(ll n) {
	vb t(n+1, true); t[0] = t[1] = false;
	for(ll i = 2; i <= n; ++i) if (t[i]){
		for(ll j = 2*i; j <= n; j += i) t[j] = false;
	}
	return t;
}
vl compress(const vb & t) {
	vl v; v.reserve((ll)(1.2 * t.size() / log(t.size())));
	REP(i, t.size()) if (t[i]) v.push_back(i);
	return v;
}

ll min_prime(ll n) {
	FOR(i, 2, sqrt(n)+1) if (n%i == 0) return i;
	return 1;
}

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	ll n, m; cin >> n >> m;

	auto e = eratosthenes(sqrt(m) + 1);
	auto er = compress(e);
	if (er.back() * er.back() >= n) {
		ll ma = er.back()*er.back();
		for (ll i = er.back(); i*er.back() <= m; ++i) ma = er.back()*i;
		cout << ma << endl;
		return 0;
	}

	ll ma = 1;
	ll mai = 1;
	for (ll i = m; i >= n; --i) {
		ll x = min_prime(i);
		if (ma < x) {
			ma = x;
			mai = i;
		}
	}

	cout << mai << endl;
	return 0;
}
0