結果
| 問題 | No.3253 Banned Product |
| コンテスト | |
| ユーザー |
vjudge1
|
| 提出日時 | 2025-11-20 22:25:20 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,064 bytes |
| コンパイル時間 | 1,869 ms |
| コンパイル使用メモリ | 197,868 KB |
| 実行使用メモリ | 7,852 KB |
| 最終ジャッジ日時 | 2025-11-20 22:25:22 |
| 合計ジャッジ時間 | 2,783 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 2 WA * 7 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
const int MAXP = 1000010;
vector<int> primes;
bitset<MAXP> isp;
void sieve() {
isp.set(); isp[0]=isp[1]=0;
for (long long i = 2; i < MAXP; i++) if (isp[i]) {
primes.push_back(i);
for (long long j = i*i; j < MAXP; j += i) isp[j]=0;
}
}
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
sieve();
int T; cin >> T;
while (T--) {
int n, k; cin >> n >> k;
if (n == k) { cout << "-1\n"; continue; }
long long ans = -1;
// Try every prime p > k
for (int p : primes) {
if (p > k) {
if (p > n) break;
ans = max(ans, (long long)(n / p) * p);
}
}
// If n itself has a prime factor > k ? n is also a candidate
int x = n;
for (int p : primes) {
if ((long long)p * p > x) break;
while (x % p == 0) x /= p;
}
if (x > k) ans = max(ans, (long long)n);
cout << (ans == -1 ? -1 : ans) << "\n";
}
}
vjudge1