結果

問題 No.371 ぼく悪いプライムじゃないよ
ユーザー togari_takamototogari_takamoto
提出日時 2016-05-13 23:59:53
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 373 ms / 1,000 ms
コード長 1,854 bytes
コンパイル時間 1,325 ms
コンパイル使用メモリ 151,100 KB
実行使用メモリ 6,876 KB
最終ジャッジ日時 2023-08-29 00:54:20
合計ジャッジ時間 4,138 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,384 KB
testcase_13 AC 1 ms
4,384 KB
testcase_14 AC 1 ms
4,384 KB
testcase_15 AC 2 ms
4,388 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,384 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,384 KB
testcase_22 AC 6 ms
4,380 KB
testcase_23 AC 6 ms
4,380 KB
testcase_24 AC 45 ms
6,792 KB
testcase_25 AC 45 ms
6,820 KB
testcase_26 AC 373 ms
6,660 KB
testcase_27 AC 44 ms
6,576 KB
testcase_28 AC 43 ms
6,284 KB
testcase_29 AC 44 ms
6,876 KB
testcase_30 AC 43 ms
6,488 KB
testcase_31 AC 43 ms
6,680 KB
testcase_32 AC 44 ms
6,468 KB
testcase_33 AC 43 ms
6,440 KB
testcase_34 AC 39 ms
6,128 KB
testcase_35 AC 42 ms
6,216 KB
testcase_36 AC 24 ms
5,008 KB
testcase_37 AC 44 ms
6,284 KB
testcase_38 AC 39 ms
6,064 KB
testcase_39 AC 41 ms
6,464 KB
testcase_40 AC 42 ms
6,360 KB
testcase_41 AC 41 ms
6,072 KB
testcase_42 AC 37 ms
6,184 KB
testcase_43 AC 42 ms
6,596 KB
testcase_44 AC 38 ms
5,540 KB
testcase_45 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

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()
#define TEN(x) ((ll)1e##x)
 
template<typename T> inline string join(const vector<T>& vec, string sep = " ") { stringstream ss; REP(i, vec.size()) ss << vec[i] << ( i+1 == vec.size() ? "" : sep ); return ss.str(); }

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) {
	ll x = sqrt(n);
	FOR(i, 2, x+1) if (n%i == 0) return i;
	return 1;
}

int main() {
#ifdef INPUT_FROM_FILE
	ifstream cin("sample.in");
	ofstream cout("sample.out");
#endif
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	ll n, m; cin >> n >> m;

	auto e = eratosthenes(sqrt(m)*50);
	auto er = compress(e);
	ll index = er.size() - 1;
	while (index >= 0 && er[index] * er[index] > m) index--;

	while (index>0) {
		ll ma = -1;
		for (ll i = index; i < er.size() && er[i] * er[index] <= m; ++i) {
			if(er[i] * er[index] >= n) ma = er[i] * er[index];
		}
		if (ma != -1) {
			cout << ma << endl;
			return 0;
		}
		index--;
	}
	

	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