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

    ID: 16763 Type: RemoteJudge 2000ms 512MiB Tried: 0 Accepted: 0 Difficulty: 6 Uploaded By: Tags>高精度2017二分ICPC双指针 two-pointer香港

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

题目描述

Consider the error function F(x,y,z,n)=∣xn+yn−zn∣F(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.

输入格式

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).

输出格式

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