ACM—数论—费马大定理 (数学史上著名的定理)

百度词条

费马大定理,又被称为“费马最后的定理”,由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 a^n+b^n=c^n
.
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^n=c^n,给出a,n,求是否存在b,c满足题意。

 n>2时由费马大定理知无解,n=0时易知无解,n=1无脑输出答案即可。

只有n==2的情况,根据奇偶数列法则可得。

代码如下:

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

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值