#P6299. 差别

    ID: 5216 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>数学2020Special Judge扩展欧几里德,扩欧构造

差别

Description

Define the difference measure between integers p,q,r,sp,q,r,s and the given integers a,b,c,da,b,c,d as

$$M=\Big|\left(a^2+b^2\right)\left(p^2+q^2\right)+\left(c^2+d^2\right)\left(r^2+s^2\right)+2\big(ac+bd\big)\big(pr-qs\big)+2\big(bc-ad\big)\big(ps+qr\big)\Big|$$

Your task is to find the smallest non-zero value of the difference measure MM, and one set of p,q,r,sp,q,r,s that achieves this smallest non-zero value. It is guaranteed that the smallest non-zero value of MM exists and is less than 2632^{63}. It is also guaranteed that there exists a set of p,q,r,sp,q,r,s with all absolute values less than 2632^{63} such that MM attains the smallest non-zero value.

Input Format

Input one line with four integers a,b,c,da,b,c,d, as described above.

Output Format

Output one line with five integers p,q,r,s,Mp,q,r,s,M, representing a set of p,q,r,sp,q,r,s that makes the difference measure MM reach its smallest non-zero value, and the value of MM at that time.

1 9 2 6

2 1 -3 1 2

19674937 18722417 163948077 124500851

146134 -61558 -18260 -10209 221162

Hint

Sample Explanation #1

Obviously, when a=1,b=9,c=2,d=6a=1,b=9,c=2,d=6, the difference measure MM must be even, so MM cannot take any non-zero value smaller than 22.

Constraints

Test Point ID Special Property
11 c=d=0c=d=0
22 a=c=0a=c=0
33 b=d=0b=d=0
44 ad=bcad=bc
55 $\vert a\vert,\vert b\vert,\vert c\vert,\vert d\vert\le10$
6106\sim10 None

For 100%100\% of the testdata, $\vert a\vert,\vert b\vert,\vert c\vert,\vert d\vert\le10^9$.

Scoring Method

You must ensure that the number of values you output for each test point is 55 and that $\vert p\vert,\vert q\vert,\vert r\vert,\vert s\vert,\vert M\vert<2^{63}$, to avoid unexpected errors.

For each test point, if your MM is the same as the standard output, you will get 44 points. If the p,q,r,sp,q,r,s you output can make the computed result equal to MM, you will get another 66 points.

Translated by ChatGPT 5