【BZOJ1041】[HAOI2008]圆上的整点

bzoj

题解

$x^2+y^2=r^2\\ y^2=(x+r)(x-r)$

$r-x=ud,r+x=vd,(u,v)=1$

$y^2=d^2uv$

$u,v$一定为完全平方数
$u=s^2,v=t^2$且必有$(s,t)=1$

$2r=(u+v)d=(s^2+t^2)d\\ \Rightarrow\\ x=\frac{t^2-s^2}{2}d\\ y=dst\$

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long ll;
ll R, ans;
int main () {
cin >> R;
for (ll i = 1; i * i <= 2 * R; i++) {
if (2 * R % i == 0) {
ll d = i;
for (ll s = 1; s * s <= 2 * R / d; s++) {
ll t = sqrt(2 * R / d - s * s);
if (s * s + t * t == 2 * R / d && __gcd(s, t) == 1) {
ll x = (t * t - s * s) / 2 * d, y = d * s * t;
if (x > 0 && y > 0 && x * x + y * y == R * R) ans += 2;
}
}
if (i * i != R) {
d = 2 * R / i;
for (ll s = 1; s * s <= 2 * R / d; s++) {
ll t = sqrt(2 * R / d - s * s);
if (s * s + t * t == 2 * R / d && __gcd(s, t) == 1) {
ll x = (t * t - s * s) / 2 * d, y = d * s * t;
if (x > 0 && y > 0 && x * x + y * y == R * R) ans += 2;
}
}
}
}
}
printf("%lld\n", (ans + 1) * 4);
return 0;
}

posted @ 2018-12-26 10:56  heyujun  阅读(72)  评论(0编辑  收藏