#P17181. [ICPC 2017 Hong Kong R] Fermat's Optimization Problem

    ID: 19435 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 显示难度暂无评定 上传者: 标签>2017Special JudgeICPC香港

[ICPC 2017 Hong Kong R] Fermat's Optimization Problem

Problem Description

Consider the error function F(x,y,z,n)=xn+ynznF(x, y, z, n) = |x^n + y^n - z^n|, where v|v| means the absolute value of vv. Given two positive integers nn and zz, our problem is to find two positive integers xx and yy such that x<y<zx < y < z and the error value F(x,y,z,n)F(x, y, z, n) is minimized. There may be multiple values of xx and yy that minimize F(x,y,z,n)F(x, y, z, n), and you may output any of them.

For example, if we are given n=3n = 3 and z=9z = 9, then the solution is: x=6x = 6 and y=8y = 8. This solution yields the error value 11.

Input Format

The first line contains the number of test cases TT (T<10T < 10). Each subsequent line corresponds to a test case, which contains two positive integers nn (2<n<102 < n < 10) and zz (1<z<1000001 < z < 100000).

Output Format

For each test case, output the value of xx, yy, and F(x,y,z,n)F(x, y, z, n) in a line, separated by spaces.

2
3 9
3 7
6 8 1
5 6 2