hdu 6441 Find Integer(费马大定理+智慧数)

Problem Description

people in USSS love math very much, and there is a famous math problem .
give you two integers n,a,you are required to find 2 integers b,c such that an+bn=cn.

Input

one line contains one integer T;(1T1000000)
next T lines contains two integers n,a;(0n1000,000,000,3a40000)

Output

print two integers b,c if b,c exits;(1b,c1000,000,000);
else print two integers -1 -1 instead.

Sample Input

1
2 3

Sample Output

4 5
解题思路:①费马大定理:当整数n>2时,关于x, y, z的方程 x^n + y^n = z^n 没有正整数解。
②智慧数:一个自然数若能表示为两个自然数的平方差,则这个自然数为“智慧数”。形如2k+1或4k的形式必为智慧数,k≥0。举个栗子:验证2687是否为智慧数,∵2687为奇数,∴设2687=2k+1(k为正整数),∴k=1343,∴2687=1344²-1343²,∴2687是智慧数。验证16是否为智慧数,∵4|16,∴k=4,∴16=52-32,∴16为智慧数。
AC代码:
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int t,n,a;
 4 int main(){
 5     while(~scanf("%d",&t)){
 6         while(t--){
 7             scanf("%d%d",&n,&a);
 8             if(!n||n>2)printf("-1 -1
");//无解
 9             else if(n==1)printf("%d %d
",1,a+1);//输出最小即可
10             else{
11                 a*=a;
12                 if(a&1)printf("%d %d
",a/2,a/2+1);//奇数
13                 else{
14                     if(a%4)printf("-1 -1
");//无解
15                     else printf("%d %d
",a/4-1,a/4+1);
16                 }
17             }
18         }
19     }
20     return 0;
21 }
原文地址:https://www.cnblogs.com/acgoto/p/9824154.html