import java
.io
.*;
import java
.math
.*;
import java
.util
.*;
import java
.text
.*;
public class Main
{
public static void main(String
[] args
)
{
Scanner cin
= new Scanner (new BufferedInputStream(System
.in));
BigInteger
[][] p
= new BigInteger[100001][11];
for(int i
=1;i
<100001;i
++)
{
p
[i
][0]=new BigInteger("1");
for(int j
=1;j
<=10;j
++) p
[i
][j
]=p
[i
][j
-1].multiply(BigInteger
.valueOf(i
));
}
BigInteger zero
= new BigInteger("0");
BigInteger one
= new BigInteger("1");
BigInteger
INF=one
;
for(int i
=0;i
<10;i
++) INF=INF.multiply(p
[10][10]);
int t
,z
,n
;
t
=cin
.nextInt();
while((t
--)>0)
{
n
= cin
.nextInt();z
= cin
.nextInt();
int x
=0,y
=0;
BigInteger res
=INF;
BigInteger num
;
for(int i
=2;i
<z
;i
++)
{
int l
=1,r
=i
-1;
while(l
<r
)
{
int mid
=l
+r
+1>>1;
num
= p
[mid
][n
].add(p
[i
][n
]).subtract(p
[z
][n
]);
if(num
.compareTo(zero
)<0) l
=mid
;
else r
=mid
-1;
}
num
=p
[r
][n
].add(p
[i
][n
]).subtract(p
[z
][n
]);
if(num
.compareTo(zero
)>=0)
{
if(num
.compareTo(res
)<0)
{
res
=num
;
x
=r
;
y
=i
;
}
}
else
{
num
=num
.multiply(new BigInteger("-1"));
if(num
.compareTo(res
)<0)
{
res
=num
;
x
=r
;
y
=i
;
}
if(r
<i
-1)
{
r
++;
num
=p
[r
][n
].add(p
[i
][n
]).subtract(p
[z
][n
]);
if(num
.compareTo(res
)<0)
{
res
=num
;
x
=r
;
y
=i
;
}
}
}
}
System
.out
.printf("%d %d ", x
, y
);
System
.out
.println(res
);
}
}
}
转载请注明原文地址:https://blackberry.8miu.com/read-18331.html