niuke --- Pythagorean theorem

------ Pythagorean theorem:

Wherein when a number greater than 1 and a is an odd number i.e. a = 2 * n + 1, then the other two numbers are b = 2 * n * n + 2 * n; c = b + 1;

When a is an even number greater than or equal to 4, i.e., when a = 2 * n, then the other two numbers are b = n * n-1 c = n * n + 1;

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll a;
    cin>>a;
    if(a>1 && a&1) {
        ll x=(a-1)/2;
        ll y=2*x*x+2*x;
        cout<<y<<" "<<y+1<<endl;
    }
    else if(a>=4 && a%2==0) {
        ll xx=a/2;
        ll yy=xx*xx+1;
        cout<<yy<<" "<<yy-2<<endl;
    }
    else cout<<-1<<endl;
     
    return 0;
} 

 

Guess you like

Origin www.cnblogs.com/Accepting/p/11479309.html