Luo Gu [P5596] [title] XR-4

solution

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

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

When \ (x ^ 2 + ax + b \) when perfect square \ (Ans = inf \)

\ (x \ leq y \) might Order \ (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}\)

Enumeration, to find what makes \ (x \) is a natural number \ (t \) , count the number that is \ (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;
}

Guess you like

Origin www.cnblogs.com/yjkhhh/p/11712450.html