loj3257. 「ROIR 2020 Day 1」平方差

3257. 「ROIR 2020 Day 1」平方差


Sol

比较水的一道题。

$(x+y)(x-y)=n^2$

x+y和x-y奇偶性要相同

若n为奇数 1*n成立 。

若n为偶数 x=n/2;

  若x为奇数就是No (无法划分成奇偶性相同的两块)

  若x为偶数就是Yes

注意判0 1 4即可。

#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#define ll long long
using namespace std;
ll n;
int main(){
    scanf("%lld",&n);
    if(n==1||n==4){puts("No");return 0;}
    if(n==0){puts("Yes
1 1
");return 0;}
    if(n&1)printf("Yes
%lld %lld
",(n+1)>>1,((n+1)>>1)-1);
    else {
        n>>=1;
        if(n%2==0){
            ll x=(2+n)/2,y=x-2;
            printf("Yes
%lld %lld
",x,y);
        }
        else puts("No");
    }
    return 0;
}
View Code
原文地址:https://www.cnblogs.com/liankewei/p/12405162.html