ccpc2018网络赛 1004

链接

http://acm.hdu.edu.cn/showproblem.php?pid=6441

给a,n求b,c使得a^n+b^n=c^n

由费马大定理知当n>2时候没有正整数解

当n=0时 无解

当n=1时 a=c-b 构造 c=a+1 b=1;

当n=2时 a2=c2-b2

令c=x+y b=x-y

(x+y)^2-(x-y)^2=4xy

所以构造 xy=a^2/4 即可

并且 x+y和x-y都要是整数

所以 a%2=1时 x+y=(a2+1)/2 

a%2=0时 x+y=a2/4 + 1

上代码

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
using namespace std;
typedef long long ll;
ll n,a;
int main()
{
    int cas;
    scanf("%d",&cas);
    while (cas--)
    {
        scanf("%lld%lld",&n,&a);
        if (n>2)
            printf("-1 -1\n");
        else
        {
            if (n==0)
                printf("-1 -1\n");
            if (n==1)
                printf("1 %lld\n",1+a);
            if (n==2)
            {
                if (a%2==1)
                    printf("%lld %lld\n",(a*a-1)/2,(a*a+1)/2);
                else printf("%lld %lld\n",a*a/4-1,a*a/4+1);
            }
        }
    }
    return 0;
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值