import std.conv, std.functional, std.range, std.stdio, std.string; import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons; import core.bitop; class EOFException : Throwable { this() { super("EOF"); } } string[] tokens; string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; } int readInt() { return readToken.to!int; } long readLong() { return readToken.to!long; } real readReal() { return readToken.to!real; } bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } } bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } } int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; } int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); } int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); } alias Frac = Tuple!(long, "p", long, "q"); int cmp(Frac a, Frac b) { const d = a.p * b.q - b.p * a.q; return (d < 0) ? -1 : (d > 0) ? +1 : 0; } void main() { try { for (; ; ) { const numCases = readInt; foreach (caseId; 0 .. numCases) { const N = readInt; const K = readLong; // p/q <= l/N long calc(int l) { auto fs = new long[N + 1]; foreach (d; 1 .. N + 1) { const n = N / d; if (d > 1 && N / (d - 1) == n) { fs[d] = fs[d - 1]; } else { foreach (q; 1 .. n + 1) { fs[d] += min(q - 1, cast(long)(q) * l / N); } } } foreach_reverse (d; 1 .. N + 1) { for (int e = 2 * d; e <= N; e += d) { fs[d] -= fs[e]; } } debug { writefln("calc %s = %s", l, fs[1]); } return fs[1]; } Frac solve(long k) { int lo = 0, hi = N; for (; lo + 1 < hi; ) { const mid = (lo + hi) / 2; ((calc(mid) >= k) ? hi : lo) = mid; } debug { writefln("solve %s: lo = %s, hi = %s", k, lo, hi); } k -= calc(lo); const a0 = Frac(lo, N); Frac[] bs; foreach (q; 1 .. N + 1) { const p = cast(long)(q) * hi / N; if (0 < p && p < q && gcd(p, q) == 1) { const b = Frac(p, q); if (cmp(a0, b) < 0) { bs ~= b; } } } bs.sort!((a, b) => (cmp(a, b) < 0)); debug { writeln("bs = ", bs); } return bs[k - 1]; } const num = calc(N); Frac ans; if (K <= num) { ans = solve(K); } else if (K == num + 1) { ans = Frac(1, 1); } else if (K <= num + 1 + num) { ans = solve((num + 1 + num) + 1 - K); swap(ans.p, ans.q); } if (ans.q) { writefln("%s/%s", ans.p, ans.q); } else { writeln(-1); } } } } catch (EOFException e) { } }