您的位置:首页 > 其它

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

2016-04-19 12:29 260 查看
和 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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: