D - Find Integer

 

D - Find Integer

$a^{n}+b^{n}=c^{n}$

Given a, n solving $ b, c $

 No more than three times the integer solution

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll A[500005];
ll n,a;
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%lld%lld",&n,&a);

        if(n>=3)
        {
            puts("-1 -1");
        }
        else if(n==1)
        {
            cout<<1<<' '<<a+1<<'\n';
        }
        else if(n==0)
        {
            cout<<-1<<' '<<-1<<'\n';
        }
        else
        {
            ll b,c,x,y;
            for(ll i=1; i<a; i++)
            {
                if((a*a)%i==0)
                {
                    x=(a*a)/i;
                    y=i;
                   // cout<<(x+y)<<" "<<a<<endl;
                    if((x+y)%2==0&&(x+y)!=(2*a))break;
                }
            }
            c=(x+y)/2;
            b=sqrt(c*c-a*a);
            cout<<b<<' '<<c<<'\n';
        }
    }
}

 

Guess you like

Origin www.cnblogs.com/liulex/p/11367554.html