結果
| 問題 | No.3485 Find 495-like Number |
| コンテスト | |
| ユーザー |
hiromi_ayase
|
| 提出日時 | 2026-03-27 23:11:31 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,519 bytes |
| 記録 | |
| コンパイル時間 | 6,095 ms |
| コンパイル使用メモリ | 376,368 KB |
| 実行使用メモリ | 19,128 KB |
| 最終ジャッジ日時 | 2026-03-27 23:12:15 |
| 合計ジャッジ時間 | 12,341 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 1 TLE * 1 -- * 32 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
#define FAST_IO \
ios::sync_with_stdio(false); \
cin.tie(0);
const i64 INF = 1001001001001001001;
using Modint = atcoder::static_modint<998244353>;
vector<i64> getPrimes(int n) {
vector<bool> isPrime(n + 1, true);
isPrime[0] = isPrime[1] = false;
for (int i = 2; i <= n; i ++) {
if (isPrime[i]) {
for (int j = i + i; j <= n; j += i) {
isPrime[j] = false;
}
}
}
vector<i64> primes;
for (int i = 3; i <= n; i ++) {
if (isPrime[i]) {
primes.push_back(i);
}
}
return primes;
}
template<class T> T pow_mod(T A, T N, T M) {
T res = 1 % M;
A %= M;
while (N) {
if (N & 1) res = (res * A) % M;
A = (A * A) % M;
N >>= 1;
}
return res;
}
bool MillerRabin(long long N, vector<long long> A) {
long long s = 0, d = N - 1;
while (d % 2 == 0) {
++s;
d >>= 1;
}
for (auto a : A) {
if (N <= a) return true;
long long t, x = pow_mod<__int128_t>(a, d, N);
if (x != 1) {
for (t = 0; t < s; ++t) {
if (x == N - 1) break;
x = __int128_t(x) * x % N;
}
if (t == s) return false;
}
}
return true;
}
bool is_prime(long long N) {
if (N <= 1) return false;
if (N == 2) return true;
if (N % 2 == 0) return false;
if (N < 4759123141LL)
return MillerRabin(N, {2, 7, 61});
else
return MillerRabin(N, {2, 325, 9375, 28178, 450775, 9780504, 1795265022});
}
int main() {
FAST_IO
i64 L, R;
cin >> L >> R;
auto primes = getPrimes(10000000);
int m = primes.size();
for (int i = 0; i < m; i ++) {
auto a = primes[i];
if (a * a * a * a >= R) break;
for (int j = i + 1; j < m; j ++) {
auto b = primes[j];
if (a * a * b * b >= R) break;
auto x = a * a * b;
auto y = (L + x - 1) / x;
if (y >= 1e4) {
for (i64 c = y; x * c <= R; c ++) {
if (is_prime(c)) {
cout << x * c << endl;
return 0;
}
}
}
for (int k = j + 1; k < m; k ++) {
auto c = primes[k];
auto x = a * a * b * c;
if(L <= x && x <= R) {
cout << x << endl;
return 0;
}
if (x >= R) break;
}
}
}
cout << -1 << endl;
return 0;
}
hiromi_ayase