您的位置:首页 > 其它

【BZOJ1041】[HAOI2008]圆上的整点【数学】

2016-03-28 20:25 381 查看
【题目链接】

奇怪的姿势。

【csyzcyj的题解】

/* Footprints In The Blood Soaked Snow */
#include <cstdio>
#include <cmath>

typedef long long LL;

LL R;

inline int gcd(LL a, LL b) {
for(; b; b ^= a ^= b ^= a %= b);
return a;
}

inline bool check(LL x, double y) {
if(y == (LL)y) {
LL y1 = (LL)y;
if(gcd(x * x, y1 * y1) == 1 && x != y1) return 1;
}
return 0;
}

int main() {
scanf("%lld", &R);
LL _2R = 2.0 * R, _sqrt2R = sqrt(_2R), ans = 0;
for(int d = 1; d <= _sqrt2R; d++)
if(_2R % d == 0) {
LL upb = sqrt(_2R / (2 * d));
for(int a = 1; a <= upb; a++) {
double b = sqrt(_2R / d - a * a);
if(check(a, b)) ans++;
}
if(d != _2R / d) {
LL upb = sqrt(d / 2);
for(int a = 1; a <= upb; a++) {
double b = sqrt(d - a * a);
if(check(a, b)) ans++;
}
}
}
printf("%lld\n", ans * 4 + 4);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: