結果
| 問題 |
No.371 ぼく悪いプライムじゃないよ
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-12-05 15:29:33 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,538 bytes |
| コンパイル時間 | 1,391 ms |
| コンパイル使用メモリ | 170,256 KB |
| 実行使用メモリ | 13,756 KB |
| 最終ジャッジ日時 | 2024-07-07 07:50:54 |
| 合計ジャッジ時間 | 4,460 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 20 TLE * 1 -- * 21 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
os << "[";
for (int 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 int maxN = 1e5 + 7;
vector<int>p(maxN + 7, true);
vector<int>tt;
void go() {
p[1] = false;
p[0] = false;
for (int i = 2; i <= maxN; i++) {
if (p[i]) {
tt.push_back(i);
for (int j = 2 * i; j <= maxN; j += i) {
p[j] = false;
}
}
}
}
int ok(int n) {
for (int i = 2; i * i <= n; i++) {
if (n % i == 0) {
return i;
}
}
return n;
}
void solve() {
long long l, r;
cin >> l >> r;
long long ans = 0;
for (int 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() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int T;
//cin >> T;
T = 1;
while (T--) {
go();
solve();
}
}