結果

問題 No.3253 Banned Product
コンテスト
ユーザー vjudge1
提出日時 2025-11-20 22:22:19
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 1,219 bytes
コンパイル時間 1,814 ms
コンパイル使用メモリ 198,864 KB
実行使用メモリ 141,236 KB
最終ジャッジ日時 2025-11-20 22:22:28
合計ジャッジ時間 8,563 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample TLE * 1
other -- * 9
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define vi vector<int>
#define pb push_back
#define fast ios::sync_with_stdio(false); cin.tie(nullptr);

vi seive(int n){
    vector<bool> prime(n+1, true);
    prime[0] = prime[1] = false;

    for(int i=2; i*i<=n; i++){
        if(prime[i]){
            for(int j=i*i; j<=n; j+=i){
                prime[j] = false;
            }
        }
    }

    vi res;
    for(int i=2; i<=n; i++){
        if(prime[i]) res.pb(i);
    }
    return res;
}

vi primes = seive(1e9);

// Correct factorisation
vi factorisation(int n, const vi &primes){
    vi factors;
    for(int p : primes){
        if(1LL * p * p > n) break;
        while(n % p == 0){
            factors.pb(p);
            n /= p;
        }
    }
    if(n > 1) factors.pb(n);
    return factors;
}

void solve(){
    int n, k;
    cin >> n >> k;

    if(n == k){
        cout << -1 << "\n";
        return;
    }

    for(int i = n; i >= 1; i--){
        vi arr = factorisation(i, primes);
        if(arr.back() > k){
            cout << i << "\n";
            return;
        }
    }
}

int main(){
    fast
    int t = 1;
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}
0