圆上的整点 HYSBZ - 1041 数论

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

Input

只有一个正整数n,n<=2000 000 000

Output

整点个数 

Sample Input
4
Sample Output
4


详细解释

Orz

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<ctime>
#include<deque>
#include<stack>
#include<functional>
#include<sstream>
#include<cctype>
//#pragma GCC optimize("O3")
using namespace std;
#define maxn 200005
#define inf 0x3f3f3f3f
#define INF 0x7fffffff
#define rdint(x) scanf("%d",&x)
#define rdllt(x) scanf("%lld",&x)
typedef long long  ll;
typedef unsigned long long ull;
typedef unsigned int U;
#define ms(x) memset((x),0,sizeof(x))
const int mod = 10000007;
#define Mod 20100403
#define sq(x) (x)*(x)
#define eps 1e-10


inline int rd() {
	int x = 0;
	char c = getchar();
	bool f = false;
	while (!isdigit(c)) {
		if (c == '-') f = true;
		c = getchar();
	}
	while (isdigit(c)) {
		x = (x << 1) + (x << 3) + (c ^ 48);
		c = getchar();
	}
	return f ? -x : x;
}

ll gcd(ll a, ll b) {
	return b == 0 ? a : gcd(b, a%b);
}
ll sqr(ll x) { return x * x; }

bool check(ll y, double x) {
	if (x == floor(x)) {
		ll x1 = (ll)floor(x);
		if (gcd(x1*x1, y*y) == 1 && x1*x1 != y * y)
			return true;
	}
	return false;
}



int main()
{
	//ios::sync_with_stdio(false);
	ll R, ans = 0;
	rdllt(R);
	for (ll d = 1; d <= sqrt(2 * R); d++) {
		if ((2 * R) % d == 0) {
			for (ll a = 1; a <= (ll)sqrt(2 * R / (2 * d)); a++) {
				double b = sqrt((2 * R) / d - a * a);
				if (check(a, b))ans++;
			}
			if (d != (2 * R) / d) {
				for (ll a = 1; a <= sqrt(d / 2); a++) {
					double b = sqrt(d - a * a);
					if (check(a, b))ans++;
				}
			}
		}
	}
	cout << (ll)ans * 4 + 4ll << endl;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值