【洛谷P5596】【XR-4】题

【洛谷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\times(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\n",Ans);
	return 0;
}

相关文章:

  • 2021-11-01
  • 2022-01-27
  • 2021-08-10
  • 2022-01-28
  • 2021-09-05
  • 2021-11-10
  • 2021-06-05
  • 2022-12-23
猜你喜欢
  • 2021-08-20
  • 2021-11-11
  • 2021-12-29
  • 2022-12-23
  • 2021-12-03
  • 2022-01-26
  • 2022-01-24
相关资源
相似解决方案