結果

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

ソースコード

diff #
raw source code

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

int largestPF(ll n) {
    if(n <= 1) return 0;
    int res = 0;
    while(n%2==0){ res=2; n/=2; }
    for(ll i=3; i*i<=n; i+=2){
        while(n%i==0){ res=i; n/=i; }
    }
    if(n>1) res = n;
    return res;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t; cin>>t;
    while(t--){
        ll n,k; cin>>n>>k;
        if(n==k){ cout<<"-1\n"; continue; }

        bool ok = false;
        for(ll x=n; x>=max(2LL,n-100000); x--){
            if(largestPF(x) > k){
                cout<<x<<"\n";
                ok=true;
                break;
            }
        }
        if(!ok) cout<<"-1\n";
    }
}
0