#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include #include #include #include #include #include #include #include #include #include #include #include #include #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; template vector> vec2d(int n, int m, T v){ return vector>(n, vector(m, v)); } template vector>> vec3d(int n, int m, int k, T v){ return vector>>(n, vector>(m, vector(k, v))); } template void print_vector(vector v, char delimiter=' '){ if(v.empty()) { cout << endl; return; } for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; cout << v.back() << endl; } /** * 有理数の計算用。dが分母でnが分子。 * atcoderだとたいていmodintで足りるが、Project Eulerだとたまに使える。 */ template class frac{ public: T n, d; frac(T _n, T _d){ T g = gcd(_n, _d); n = _n/g; d = _d/g; if(d < 0) { d *= -1; n *= -1; } } frac operator+(frac f){ return frac(n*f.d+d*f.n, f.d*d); } frac operator-(frac f){ return frac(n*f.d-d*f.n, f.d*d); } frac operator*(frac f){ return frac(f.n*n, f.d*d); } frac inv(){ return frac(d, n); } bool operator<(frac f){ if(d*f.d < 0) return n*f.d-d*f.n > 0; else return n*f.d-d*f.n < 0; } bool operator>(frac f){ if(d*f.d < 0) return n*f.d-d*f.n < 0; else return n*f.d-d*f.n > 0; } bool operator==(frac f){ return n*f.d-d*f.n == 0; } void operator+=(frac f){ n = n*f.d+d*f.n, d = f.d*d; reduction(); } void operator-=(frac f){ n = n*f.d-d*f.n, d = f.d*d; reduction(); } void reduction(){ T g = gcd(n, d); n /= g, d /= g; } }; template bool operator<(const frac f1, const frac f2){ if(f1.d*f2.d < 0) return f1.n*f2.d-f1.d*f2.n > 0; else return f1.n*f2.d-f1.d*f2.n < 0; } template bool operator>(const frac f1, const frac f2){ if(f1.d*f2.d < 0) return f1.n*f2.d-f1.d*f2.n > 0; else return f1.n*f2.d-f1.d*f2.n > 0; } template bool operator==(const frac f1, const frac f2){ return f1.n*f2.d-f1.d*f2.n == 0; } template ostream& operator<<(ostream& os, const frac& f){ os << f.n << '/' << f.d; return os; } class Eratosthenes{ public: int m; vector is_prime; vector primes; Eratosthenes(int m_){ m = m_; init(); } private: void init(){ is_prime.assign(m+1, true); is_prime[0] = false, is_prime[1] = false; for(int i = 2; i <= m; i++){ if(is_prime[i]){ primes.push_back(i); for(int j = 2; i*j <= m; j++) is_prime[i*j] = false; } } } }; const int N = 300000; Eratosthenes et(N); vector facs[N+1]; int meb[N+1]; void init(){ for(int x = 1; x <= N; x++) meb[x] = 1; for(int p: et.primes){ for(int i = 1; i*p <= N; i++){ if(i%p == 0){ meb[i*p] = 0; }else{ meb[i*p] *= -1; } } } for(int x = 1; x <= N; x++){ if(meb[x] == 0) continue; for(int i = 1; i*x <= N; i++){ facs[i*x].push_back(x); } } } using F = frac; const int M = 1000000000; void solve(){ ll n; ll k; cin >> n >> k; ll sum = 0; // x/m以下になるやつの個数 const ll m = n; auto count = [&](ll x){ ll ans = 0; for(int i = 1; i <= n; i++){ ll tmp = 0; ll r = n; if(x <= (n*m)/i){ r = min((x*i)/m, n); } for(int j: facs[i]){ if(j > r) break; tmp += (ll)meb[j]*(r/j); } ans += tmp; } return ans; }; if(count(n*m) < k){ cout << -1 << endl; return; } ll l = 0, r = n*m; while(r-l > 1){ ll x = (l+r)/2; if(count(x) < k) l = x; else r = x; } ll cnt_r = count(r); vector fs; for(int x = 1; x <= n; x++){ // (l/m) < y/x <= (r/m) ll yl = (l*x)/m; if(yl > n) continue; ll yr = (r*x)/m; chmin(yr, n); for(ll y = yl+1; y <= yr; y++){ if(gcd(x, y) != 1) continue; fs.push_back(F(y, x)); } } debug_value(fs.size()) sort(fs.begin(), fs.end()); ll cur = cnt_r; int diff = cur-k; cout << fs[fs.size()-diff-1] << endl; // while(cur > k){ // fs.pop_back(); // cur--; // } // cout << fs.back() << endl; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; init(); int t; cin >> t; while(t--) solve(); }