[数学] BZOJ 4544 椭圆上的整点

和 bzoj1041 圆上整点很类似




只要把A改为3*a*a枚举就行了 这种暴力233跑得太慢


#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;

inline ll Jud(ll x){
	ll isqr=sqrt(x);
	if (isqr*isqr==x) return isqr;
	return -1;
}

ll N,ans;

ll Gcd(ll a,ll b){
	if (a<b) return Gcd(b,a);
	return b?Gcd(b,a%b):a;
}

inline void Calc(ll d){
	ll c=2*N/d,a,b,A,B;
	for (b=1;b*b<=c;b++)
		if ((c-b*b)%3==0 && (a=Jud((c-b*b)/3))>0)
		{
			A=3*a*a;
			B=b*b;
			if (A!=B && Gcd(A,B)==1)
				if ((B-A)%2==0 || d%2==0)
				{
//					ll X=abs(B*d-A*d)>>1,Y=Jud(A*B*d*d/3);
					ans++;
				}
		}
}

int main()
{
	ll d,Q;
	freopen("t.in","r",stdin);
	freopen("t.out","w",stdout);
	scanf("%lld",&Q);
	while (Q--)
	{
		ans=0;
		scanf("%lld",&N); N=abs(N); 
		if (N==0) {
			printf("1\n"); continue;
		}
		for (d=1;d*d<2*N;d++)
			if (2*N%d==0)
				Calc(d),Calc(2*N/d);
		if (d*d==2*N)
			Calc(d);
		ans*=4;
		ans+=2;
		if (N%3==0 && Jud(N*N/3)!=-1) ans+=2;
		printf("%lld\n",ans);	
	}
	return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值