勾股数定理

一、勾股数
形如 一类的数称为勾股数(a,b,c为正整数)。

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;
}

 

posted on 2019-01-14 18:15  湫叶  阅读(760)  评论(0编辑  收藏  举报

导航