Problem Description

people in USSS love math very much, and there is a famous math problem .
give you two integers n.

Input

one line contains one integer )

Output

print two integers );
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\n");//无解
 9             else if(n==1)printf("%d %d\n",1,a+1);//输出最小即可
10             else{
11                 a*=a;
12                 if(a&1)printf("%d %d\n",a/2,a/2+1);//奇数
13                 else{
14                     if(a%4)printf("-1 -1\n");//无解
15                     else printf("%d %d\n",a/4-1,a/4+1);
16                 }
17             }
18         }
19     }
20     return 0;
21 }

 

相关文章:

  • 2022-12-23
  • 2021-06-20
  • 2022-12-23
  • 2021-08-08
  • 2022-12-23
  • 2022-12-23
  • 2021-09-27
猜你喜欢
  • 2021-09-04
  • 2022-12-23
  • 2021-11-16
  • 2021-11-29
  • 2021-06-18
相关资源
相似解决方案