p1500 圆上的整点[HAOI2008]

版权声明:https://blog.csdn.net/huashuimu2003 https://blog.csdn.net/huashuimu2003/article/details/84971003

题目

https://www.luogu.org/problemnew/show/P2508

代码

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll R,ans=0;
ll gcd(ll a,ll b)
{
	return b?gcd(b,a%b):a;
}
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)//gcd(A,B)=1并且A!=B 
        	return true;
    }
    return false;
}
int main()
{
    scanf("%lld",&R);
    for(ll d=1;d<=(ll)sqrt(2*R);++d)
    {
        if((2*R)%d==0)
        {
            for(ll a=1;a<=(ll)sqrt(2*R/(2*d));++a)//2*a^2<2*r/d
            {
                double b=sqrt(((2*R)/d)-a*a);
            	if(check(a,b)) ans++;
        	}
            if(d!=(2*R)/d)
            {
                for(ll a=1;a<=(ll)sqrt(d/2);++a)//2*a^2<d
                {
                    double b=sqrt(d-a*a);
                    if(check(a,b)) ans++;
                }
            }
        }
    }
    printf("%lld\n",ans*4+4);
    return 0;
}

猜你喜欢

转载自blog.csdn.net/huashuimu2003/article/details/84971003