結果
| 問題 | No.3485 Find 495-like Number |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-03-27 21:33:47 |
| 言語 | C++14 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 318 ms / 5,000 ms |
| コード長 | 2,897 bytes |
| 記録 | |
| コンパイル時間 | 1,023 ms |
| コンパイル使用メモリ | 136,384 KB |
| 実行使用メモリ | 130,432 KB |
| 最終ジャッジ日時 | 2026-03-27 21:34:08 |
| 合計ジャッジ時間 | 20,285 ms |
|
ジャッジサーバーID (参考情報) |
judge3_1 / judge2_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 34 |
ソースコード
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <chrono>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using Int = long long;
template <class T> ostream &operator<<(ostream &os, const vector<T> &as);
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")
constexpr int LIM_SIEVE = 30'000'010;
constexpr int LIM_SIEVE_PI = 3'000'010;
int lpf[LIM_SIEVE + 1];
int primesLen;
int primes[LIM_SIEVE_PI];
void sieveInit(int N) {
fill(lpf, lpf + (N + 1), 0);
primesLen = 0;
}
void sieve(int N = LIM_SIEVE) {
sieveInit(N);
for (int n = 2; n <= N; ++n) {
if (!lpf[n]) {
lpf[n] = n;
primes[primesLen++] = n;
}
for (int i = 0; i < primesLen && primes[i] <= lpf[n] && primes[i] * n <= LIM_SIEVE; ++i) {
lpf[primes[i] * n] = primes[i];
}
}
}
// 3^2 * 5 * (prime gap)
constexpr int LEN = 3*3 * 5 * 1000;
Int ns[LEN];
int lens[LEN];
Int pss[LEN][4];
int main() {
sieve();
Int L, R;
for (; ~scanf("%lld%lld", &L, &R); ) {
chmin(R, L + LEN - 1);
for (int i = 0; i <= R - L; ++i) {
ns[i] = L + i;
lens[i] = 0;
}
for (Int p = 2; p <= LIM_SIEVE; ++p) if (lpf[p] == p) {
for (Int n = max((L + p - 1) / p, 2LL) * p; n <= R; n += p) {
const int i = n - L;
do {
if (lens[i] < 4) pss[i][lens[i]] = p;
++lens[i];
ns[i] /= p;
} while (ns[i] % p == 0);
}
}
for (int i = 0; i <= R - L; ++i) {
if (ns[i] > 1) {
if (lens[i] < 4) pss[i][lens[i]] = ns[i];
++lens[i];
}
}
Int ans = -1;
for (int i = 0; i <= R - L; ++i) {
if (lens[i] == 4) {
const Int *ps = pss[i];
if (3 <= ps[0] && ps[0] == ps[1] && ps[1] < ps[2] && ps[2] < ps[3]) {
ans = L + i;
break;
}
}
}
printf("%lld\n", ans);
}
return 0;
}