【洛谷P5596】【XR-4】题

solution

(y^2-x^2=ax+b)

(y^2=x^2+ax+b)

(x^2+ax+b)为完全平方式时(Ans=inf)

(x leq y) 不妨令 (y=x+t)

(x^2+2xt+t^2=x^2+ax+b)

(2xt-ax=b-t^2)

(x imes(2t-a)=b-t^2)

(x=frac{b-t^2}{2t-a})

枚举,找一下使得(x)为自然数的(t),统计个数即为(Ans)

#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define int long long
using namespace std;

int A,B,Ans;

signed main()
{
	scanf("%lld%lld",&A,&B);
	if(A%2==0&&A*A/4==B){
		puts("inf");
		return 0;
	}
	int L1=sqrt(B),L2=A/2;
	if(L1>L2) swap(L1,L2);
	for(int i=max(L1-1,0ll);i<=L2+1;++i){
		if(i*2==A||((B-i*i)<0&&(2*i-A)>0)||((B-i*i)>0&&(2*i-A)<0)) continue;
		if((B-i*i)%(2*i-A)==0) ++Ans;
	}
	printf("%lld
",Ans);
	return 0;
}
原文地址:https://www.cnblogs.com/yjkhhh/p/11712450.html