题目大意:
给出a, n
求出b, c使得ana^nan +++ bnb^nbn === cnc^ncn解题思路:
特判如下
由费马大定理得: 当nnn >>> 222时无解nnn === 000时当然也是无解的了 当nnn === 111时, 可推出:bbb === 111, ccc === aaa +++ 111 那就只剩下n = 2的情况了 套进去就是a2a^2a2 +++ b2b^2b2 === c2c^2c2 就是求勾股数然后就有:
令x = a / 2.0 当a为奇数时:b = a ∗ x − 0.5b\ =\ a\ *\ x\ -\ 0.5b = a ∗ x − 0.5c = a ∗ x + 0.5c\ =\ a\ *\ x\ +\ 0.5c = a ∗ x + 0.5 当a为偶数时:b = x ∗ x − 1b\ =\ x\ *\ x\ -\ 1b = x ∗ x − 1c = x ∗ x + 1c\ =\ x\ *\ x\ +\ 1c = x ∗ x + 1Accepted code:
#includeint T, a, n;int main() { scanf("%d", &T); while (T--) { scanf("%d %d", &n, &a); if (n == 0 || n > 2) { printf("-1 -1\n"); continue; } if (n == 1) { printf("1 %d\n", a+1); continue; } double x = a / 2.0; if (a % 2) { //判断a的奇偶性 printf("%.0lf %.0lf\n", a * x - 0.5, a * x + 0.5); } else { printf("%.0lf %.0lf\n", x * x - 1, x * x + 1); } } return 0;}