Find Integer 费马大定理+勾股数(数论)

先来看一下费马大定理:在这里插入图片描述

#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        ll n;
        ll a;
        scanf("%lld%lld",&n,&a);
        if(n==0|| n>2)   
        {
            printf("-1 -1\n");
        }
        else if(n==1)
        {
             printf("1 %lld\n",a+1);
        }
        else
        {
            ll b;
            ll c;
            ll m;
            if(a%2)
            {
                m=(a-1)/2;
                 b=m*m+(m+1)*(m+1)-1;
                c=m*m+(m+1)*(m+1);
            }
            else
            {
                m=a/2;
                b=m*m-1;
                c=m*m+1;
            }
            printf("%lld %lld\n",b,c);
        }

    }
}

©️2020 CSDN 皮肤主题: 技术黑板 设计师:CSDN官方博客 返回首页