# 勾股数定理

19 篇文章 0 订阅

x^2+y^2=z^2

1.直角三角形的两条直角边和斜边满足勾股数定理。

2. .a+b>c,a-b<c

3.当a为奇数时, a=2n+1,则 b=2n^2+2n=(a-1)^2/2+a-1     ;c=b+1;

4.当a为偶数时，a=2n,则 , b=n^2+2n=a^2/4+a    ;     c=b+2;

,  当n>2时，方程没有正解。

people in USSS love math very much, and there is a famous math problem .

give you two integers nn,aa,you are required to find 22 integers bb,cc such that anan+bn=cnbn=cn.

one line contains one integer TT;(1≤T≤1000000)(1≤T≤1000000)

next TT lines contains two integers nn,aa;(0≤n≤1000(0≤n≤1000,000000,000,3≤a≤40000)000,3≤a≤40000)

print two integers bb,cc if bb,cc exits;(1≤b,c≤1000(1≤b,c≤1000,000000,000)000);

else print two integers -1 -1 instead.

Sample Input

1
2 3

Sample Output

4 5

#include <iostream>
#include <cstdio>
using namespace std;

int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,a;
scanf("%d %d",&n,&a);
if(n!=1&&n!=2) printf("-1 -1\n");
else if(n==1) printf("1 %d\n",a+1);
else
{
long long  b,c;
if(a%2!=0)
{

b=(a-1)*(a-1)/2+a-1;
c=b+1;
}
else
{
b=a*a/4-1;
c=b+2;
}
if(a*a+b*b==c*c)
printf("%lld %lld\n",b,c);
else
printf("-1 -1\n");
}
}
return 0;
}


• 0
点赞
• 0
评论
• 0
收藏
• 一键三连
• 扫一扫，分享海报

07-11 885

04-13 1072
12-04 682
05-26 1136
10-26 841
08-26 8985
08-28 757
07-15 105
07-20 1万+
01-21 239
08-27 221
09-22