首页 > 代码库 > CodeForces - 707C

CodeForces - 707C

让我们铭记勾股数,1,2无勾股数,大于等于3的奇数:2n+1勾股数是2*n*n+2*n,2*n*n+2*n+1,大于等于3的偶数:2n为n*n+1,n*n-1。啊,gtmd勾股数!

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
ll n;
int main()
{
    scanf("%lld",&n);
    if(n==1||n==2) printf("-1\n");
    else
    {   int flag=0;
        if((n-1)%2==0)
        {   ll m=(n-1)/2;
            printf("%lld %lld\n",2*m*m+2*m,2*m*m+2*m+1);
            flag=1;
        }
        else if(n%2==0)
        {
            ll m=n/2;
            printf("%lld %lld\n",m*m-1,m*m+1);
            flag=1;
        }
        if(!flag) printf("-1\n");
    }
    return 0;
}

 

CodeForces - 707C