版权声明:沃斯里德小浩浩啊 https://blog.csdn.net/Healer66/article/details/82107081
费马大定理,又被称为“费马最后的定理”,由17世纪法国数学家皮耶·德·费玛提出。
它断言当整数n >2时,关于x, y, z的方程 x^n + y^n = z^n 没有正整数解。
德国佛尔夫斯克曾宣布以10万马克作为奖金奖给在他逝世后一百年内,第一个证明该定理的人,吸引了不少人尝试并递交他们的“证明”。
被提出后,经历多人猜想辩证,历经三百多年的历史,最终在1995年被英国数学家安德鲁·怀尔斯彻底证明。
2018 CCPC 网赛的一题
1004 Find Integer
Problem
people in USSS love math very much, and there is a famous math problem .
give you two integers , ,you are required to find integers , such that
.
Input
one line contains one integer T ;
next lines contains two integers n,a;
Output
print two integers , if , exits b,c print one of the answers
else print two integers -1 -1 instead.
Sample Input
1
2 3
Sample Output
4 5
对于,给出a,n,求是否存在b,c满足题意。
n>2时由费马大定理知无解,n=0时易知无解,n=1无脑输出答案即可。
只有n==2的情况,根据奇偶数列法则可得。
代码如下:
扫描二维码关注公众号,回复:
2920642 查看本文章
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
#define ll long long
ll T, a, b, c, n;
int main()
{
cin>>T;
while(T--)
{
cin>>n>>a;
if(n == 2)
{
if(a%2)
{
ll t = (a-1)/2;
c = t*t+(t+1)*(t+1);
b = c-1;
}
else
{
ll t = (a+2)/2;
c = 1+(t-1)*(t-1);
b = c-2;
}
cout<<b<<' '<<c<<endl;
}
else if( n == 1)
{
cout<<1<<' '<<a+1<<endl;
}
else
{
cout<<-1<<' '<<-1<<endl;
}
}
}