#define CP_BUNDLED_SOURCE #ifndef CP_BUNDLE_HEADER_3840A09F237A779E #define CP_BUNDLE_HEADER_3840A09F237A779E #ifdef TEMPLATE #else #define TEMPLATE # pragma GCC optimize("O3") #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using uint=unsigned; using ll=long long; using ull=unsigned long long; using ld=long double; using pii=pair; using pll=pair; using i128=__int128; using u128=unsigned __int128; templateusing vc=vector; templateusing vvc=vc>; templateusing vvvc=vvc>; templateusing smpq=priority_queue,greater>; templateusing bipq=priority_queue; #define rep(i,n) for(ll i=0;i<(ll)(n);i++) #define REP(i,j,n) for(ll i=(j);i<(ll)(n);i++) #define DREP(i,n,m) for(ll i=(n);i>=(m);i--) #define drep(i,n) for(ll i=((n)-1);i>=0;i--) #define rall(x) x.rbegin(),x.rend() #define mp(...) make_pair(__VA_ARGS__) #define pb push_back #define fi first #define se second #define is insert #define bg begin() #define ed end() #define all(x) x.begin(),x.end() void scan(int&a) { cin >> a; } void scan(ll&a) { cin >> a; } void scan(string&a) { cin >> a; } void scan(char&a) { cin >> a; } void scan(uint&a) { cin >> a; } void scan(ull&a) { cin >> a; } void scan(bool&a) { cin >> a; } void scan(ld&a){ cin>> a;} template void scan(vector&a) { for(auto&x:a) scan(x); } void read() {} template void read(Head&head, Tail&... tail) { scan(head); read(tail...); } #define INT(...) int __VA_ARGS__; read(__VA_ARGS__); #define LL(...) ll __VA_ARGS__; read(__VA_ARGS__); #define ULL(...) ull __VA_ARGS__; read(__VA_ARGS__); #define STR(...) string __VA_ARGS__; read(__VA_ARGS__); #define VC(type, name, ...) vector name(__VA_ARGS__); read(name); #define VVC(type, name, size, ...) vector> name(size, vector(__VA_ARGS__)); read(name); templatevoid print(T a) { cout << a; } template void print(vectora) { for(int i=0;i<(int)a.size();i++){if(i)cout<<" ";print(a[i]);}cout< void PRT(T a) { print(a); cout < void PRT(Head head, Tail ... tail) { print(head); cout << " "; PRT(tail...); return; } template bool chmin(T &x, F y){ if(x>y){ x=y; return true; } return false; } template bool chmax(T &x, F y){ if(x T floor(T a, T b) { return a / b - (a % b && (a ^ b) < 0); } template T ceil(T x, T y) { return floor(x + y - 1, y); } template T bmod(T x, T y) { return x - y * floor(x, y); } template pair divmod(T x, T y) { T q = floor(x, y); return {q, x - q * y}; } void YesNo(bool b){ cout<<(b?"Yes":"No")<stovi(const string&s,const string&S){ vcv(s.size()); rep(i,s.size()){ auto t=S.find(s[i]); assert(t!=string::npos); v[i]=t; } return v; } template T isqrt(T x){ T F=sqrtl(x); while((F+1)*(F+1)<=x)F++; while(F*F>x)F--; return F; } template vvctrans(const vvc&a){ assert(a.size()&&a[0].size()); vvcb(a[0].size(),vc(a.size())); rep(i,a.size())rep(j,a[0].size()){ b[j][i]=a[i][j]; } return b; } template vctrans(const vc&a){ assert(a.size()&&a[0].size()); vcb(a[0].size(),string(a.size(),0)); rep(i,a.size())rep(j,a[0].size()){ b[j][i]=a[i][j]; } return b; } template int popcount(T n){ return __builtin_popcountll(n); } template L sum(vc&a){ return accumulate(all(a),L(0)); } template vcsubset(T S){ vcans; for(T x=S;x>0;x=(x-1)&S)ans.pb(x); ans.pb(0); return ans; } template T max(vc&a){ return *max_element(all(a)); } template T min(vc&a){ return *min_element(all(a)); } template vc presum(vc &a){ vc ret(a.size()+1); rep(i,a.size())ret[i+1]=ret[i]+a[i]; return ret; } template vc &operator+=(vc &a,F b){ for (auto&v:a)v += b; return a; } template vc &operator-=(vc&a,F b){ for (auto&v:a)v-=b; return a; } template vc &operator*=(vc&a,F b){ for (auto&v:a)v*=b; return a; } template constexpr T pow(T a,T b){ T res=1; while(b){ if(b&1)res*=a; a*=a; b/=2; } return res; } constexpr ll ten(ll a){ return pow(10,a); } templateconstexpr T inf=numeric_limits::max()/2-1; template int tbit(T x){ using U=make_unsigned_t; U y=(U)x; return y?(int)bit_width(y)-1:-1; } template int lbit(T x){ using U=make_unsigned_t; U y=(U)x; return y?(int)countr_zero(y):-1; } template int tbit(T x,int p){ using U=make_unsigned_t; constexpr int W=numeric_limits::digits; U y=(U)x; if(p<0)return -1; if(p>=W-1)return tbit(y); return tbit(y&((U(1)<<(p+1))-1)); } template int lbit(T x,int p){ using U=make_unsigned_t; constexpr int W=numeric_limits::digits; U y=(U)x; if(p<0)return lbit(y); if(p>=W)return -1; return lbit(y&(~U(0)<>(istream&is,i128&x){ string s;is>>s; x=0; int i=0,neg=0; if(s[0]=='-')neg=1,i=1; for(;i<(int)s.size();i++)x=x*10+s[i]-'0'; if(neg)x=-x; return is; } ostream& operator<<(ostream&os,i128 x){ if(x==0)return os<<0; if(x<0)os<<"-"; u128 y=x<0?-(u128)x:(u128)x; string s; while(y)s.pb('0'+y%10),y/=10; reverse(all(s)); return os<sync_with_stdio(0); #ifdef LOCAL cout< #endif #endif #endif #ifndef CP_BUNDLE_HEADER_01D6A785D0F4E280 #define CP_BUNDLE_HEADER_01D6A785D0F4E280 ull mod_mul(ull a,ull b,ull m){ return ull(static_cast(a)*b%m); } template T modpow(T a,T n,T m){ T res=1%m;a%=m; while(n){ if(n%2)res=res*a%m; a=a*a%m; n/=2; } return res; } int is_prime(ll n){ if(n<=1)return 0; if(n==2)return 1; if(n%2==0)return 0; ll k=0,q=n-1; while(q%2==0){ q/=2; k++; } auto judge=[&](vc base)->int{ for(auto x:base){ x%=n; if(x==0)continue; ll v=modpow(x,q,n); if(v!=1){ rep(i,k){ if(v==n-1)goto end; v=i128(v)*v%n; } return 0; } end:; } return 1; }; if(n<4759123141LL){ return judge({2,7,61}); }else{ return judge({2,325,9375,28178,450775,9780504,1795265022}); } } ll pollard_rho(ll n){ if(n%2==0)return 2; if(n%3==0)return 3; static mt19937_64 mt(random_device{}()); while(1){ ull y=mt()%(n-1)+1; ull c=mt()%(n-1)+1; auto f=[&](ull v){ return (mod_mul(v,v,n)+c)%n; }; ull r=1,g=1,x=0,ys=0; const ull M=128; while(g==1){ x=y; rep(i,r)y=f(y); for(ull k=0;ky?x-y:y-x; q=mod_mul(q,d,n); } g=gcd(q,(ull)n); } r*=2; } if(g==n){ do{ ys=f(ys); ull d=x>ys?x-ys:ys-x; g=gcd(d,(ull)n); }while(g==1); } if(g!=n)return g; } } void inner_factorize(ll n,vc&facts){ if(n==1)return; if(is_prime(n)){ facts.pb(n); return; } ll d=pollard_rho(n); inner_factorize(d,facts); inner_factorize(n/d,facts); } vc>factorize(ll n){ vc facts; inner_factorize(n,facts); sort(all(facts)); vc> res; for(auto p:facts){ if(res.empty()||res.back().first!=p){ res.pb({p,1}); }else{ res.back().second++; } } return res; } template vcdivisors(T x){ auto f=factorize(x); vcres; auto dfs=[&](auto&dfs,int fr,T v){ if(fr==f.size()){ res.pb(v); return; } rep(i,f[fr].second+1){ dfs(dfs,fr+1,v); v*=f[fr].fi; } }; dfs(dfs,0,1); return res; } #endif void solve(){ LL(n,k); for(ll N=n;N>=1;N--){ auto ps=divisors(N); int ok=1; for(auto&x:ps){ ok&=!(x<=k&&N/x<=k); } if(ok){ return PRT(N); } if(ps.size()==1)break; } return PRT(-1); } signed main(){ int t=1; cin >> t; while(t--)solve(); }