【BZOJ 1041】 [HAOI2008]圆上的整点

1041: [HAOI2008]圆上的整点

Time Limit: 10 Sec   Memory Limit: 162 MB
Submit: 2196   Solved: 941
[ Submit][ Status]

Description

求一个给定的圆(x^2+y^2=r^2),在圆周上有多少个点的坐标是整数。

Input

r

Output

整点个数

Sample Input

4

Sample Output

4

HINT

n<=2000 000 000




接下来枚举d,a,判断求出的b是否和题意即可。


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#define LL long long
using namespace std;
LL r;
int gcd(LL a,LL b)
{
	return a==0LL?b:gcd(b%a,a);
}
bool ok(LL a,LL b)
{
	if (a==b||gcd(a,b)!=1LL) return false;
	return true;
}
int main()
{
        scanf("%lld",&r);
	LL ans=0;
	for (LL d=1LL;d<=sqrt(2LL*r);d++)
		if ((2LL*r)%d==0LL)
		{
			for (LL a=1;a<=sqrt(r/d);a++)
			{
				LL b=sqrt(2LL*r/d-a*a);
				if (b*b!=(2LL*r/d-a*a)) continue;
				if (ok(a,b)) ans++;
			}
			if (d*d!=2LL*r)
			{
				for (LL a=1LL;a<=sqrt(d/2);a++)
				{
					LL b=sqrt(d-a*a);
					if (b*b!=d-a*a) continue;
					if (ok(a,b)) ans++;
				}
			}
		}
	cout<<ans*4LL+4LL<<endl;
	return 0;
}



感悟:

1.其实这个题挺好推的,关键是有勇气推下去。。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值