結果
| 問題 |
No.371 ぼく悪いプライムじゃないよ
|
| コンテスト | |
| ユーザー |
airis
|
| 提出日時 | 2016-05-25 00:47:37 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,338 bytes |
| コンパイル時間 | 1,888 ms |
| コンパイル使用メモリ | 161,540 KB |
| 実行使用メモリ | 13,640 KB |
| 最終ジャッジ日時 | 2024-10-07 06:52:40 |
| 合計ジャッジ時間 | 4,420 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 16 TLE * 1 -- * 25 |
ソースコード
#include <bits/stdc++.h>
#define rep(x, to) for (int x = 0; x < (to); x++)
#define REP(x, a, to) for (int x = (a); x < (to); x++)
#define EPS (1e-14)
#define _PA(x,N) rep(i,N){cout<<x[i]<<" ";}cout<<endl;
#define _PA2(x,H,W) rep(i,(H)){rep(j,(W)){cout<<x[i][j]<<" ";}cout<<endl;}
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef complex<double> Complex;
typedef vector< vector<int> > Mat;
int prime[100005];
ll L, H;
ll ans;
vector<ll> p;
void sieve_of_eratosthenes(int *a, int n) {
fill(a, a+n, 1);
a[0] = a[1] = 0;
for (int i = 2; i * i < n; i++) {
if (a[i] == 0) continue;
for (int j = i + i; j < n; j += i) {
a[j] = 0;
}
}
}
ll min_factor(ll x) {
for (int i = 0; i < p.size(); i++) {
if (x % p[i] == 0) {
return p[i];
}
}
return 1; // ありえない
}
void solve() {
rep(i, 100005) prime[i] = true;
sieve_of_eratosthenes(prime, 100005);
rep(i, 100001) {
if (prime[i] == 0) continue;
p.push_back(i);
}
for (ll i = 0; i < p.size(); i++) {
ll x = p[i];
ll s = L / x + (L % x != 0);
ll t = H / x;
ll tmp = -1;
for (ll j = s; j <= t; j++) {
ll z = min_factor(j);
if (z < x) continue;
tmp = max(tmp, x * j);
}
if (tmp != -1) ans = tmp;
}
cout << ans << endl;
}
int main() {
cin >> L >> H;
solve();
return 0;
}
airis