結果

問題 No.371 ぼく悪いプライムじゃないよ
ユーザー Mr.SpockMr.Spock
提出日時 2021-12-05 15:35:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 1,000 ms
コード長 1,519 bytes
コンパイル時間 1,395 ms
コンパイル使用メモリ 167,964 KB
実行使用メモリ 4,392 KB
最終ジャッジ日時 2023-09-21 14:02:41
合計ジャッジ時間 2,955 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,376 KB
testcase_01 AC 3 ms
4,380 KB
testcase_02 AC 3 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 3 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 3 ms
4,384 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 3 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 3 ms
4,380 KB
testcase_23 AC 3 ms
4,376 KB
testcase_24 AC 3 ms
4,380 KB
testcase_25 AC 3 ms
4,380 KB
testcase_26 AC 2 ms
4,392 KB
testcase_27 AC 3 ms
4,376 KB
testcase_28 AC 3 ms
4,376 KB
testcase_29 AC 3 ms
4,380 KB
testcase_30 AC 3 ms
4,392 KB
testcase_31 AC 3 ms
4,376 KB
testcase_32 AC 3 ms
4,376 KB
testcase_33 AC 3 ms
4,380 KB
testcase_34 AC 3 ms
4,376 KB
testcase_35 AC 3 ms
4,380 KB
testcase_36 AC 3 ms
4,376 KB
testcase_37 AC 3 ms
4,376 KB
testcase_38 AC 3 ms
4,376 KB
testcase_39 AC 3 ms
4,376 KB
testcase_40 AC 2 ms
4,380 KB
testcase_41 AC 3 ms
4,380 KB
testcase_42 AC 2 ms
4,380 KB
testcase_43 AC 3 ms
4,376 KB
testcase_44 AC 3 ms
4,376 KB
testcase_45 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os << "[";
	for (long long i = 0; i < int(v.size()); ++i) {
		os << v[i];
		if (i != v.size() - 1) {
			os << ", ";
		}
	}
	os << "]\n";
	return os;
}
template <typename T, typename U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os << "[";
	os << p.first;
	os << ", ";
	os << p.second;
	os << "]";
	return os;
}
#ifndef ONLINE_JUDGE
#define debug(x) cout << (#x) << " is " << (x) << endl
#else
#define debug(...) 42
#endif
const long long maxN = 1e5 + 7;
vector<long long>p(maxN + 7, true);
vector<long long>tt;
void go() {
	p[1] = false;
	p[0] = false;
	for (long long i = 2; i <= maxN; i++) {
		if (p[i]) {
			tt.push_back(i);
			for (long long j = 2 * i; j <= maxN; j += i) {
				p[j] = false;
			}
		}
	}
}
long long ok(long long n) {
	for (long long i = 0; i < int(p.size()); i++) {
		if (n % tt[i] == 0) {
			return tt[i];
		}
	}
	return n;
}
void solve() {
	long long l, r;
	cin >> l >> r;
	long long ans = 0;
	for (long long i = int(tt.size() - 1); i >= 0; i--) {
		if (1ll * tt[i]*tt[i] <= r) {
			long long nx = tt[i];
			long long L = max(1ll * nx * nx, l);
			long long R = r / nx * nx;
			for (long long j = R; j >= L; j -= nx) {
				long long g = ok(j);
				if (g == nx) {
					cout << j << endl;
					return ;
				}
			}
		}
	}
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	long long T;
	//cin >> T;
	T = 1;
	while (T--) {
		go();
		solve();
	}
}
0