[bzoj1041][HAOI2008]圆上的整点

我能想得出怎么做才奇怪好吗

题解:http://blog.csdn.net/csyzcyj/article/details/10044629

#include<iostream>
#include<cstdio>
#include<cmath>
#define ll long long
using namespace std;
ll read()
{
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}

ll r;
ll ans=0;

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

int main()
{
    r=read();ll to=sqrt(2*r);
    for(ll i=1;i<=to;i++)
        if(2*r%i==0)
        {
            for(ll j=1;j<=sqrt((ll)2*r/(2*i));j++)
            {
                double b=sqrt((2*r/i)-sqr(j));
                if(floor(b)==b&&sqr(j)!=sqr(floor(b))&&gcd(sqr(floor(b)),sqr(j))==1)
                    ans++;
            }
            for(ll j=1;j<=sqrt(i/2);j++)
            {
                double b=sqrt(i-sqr(j));
                if(floor(b)==b&&sqr(j)!=sqr(floor(b))&&gcd(sqr(floor(b)),sqr(j))==1)
                    ans++;
            }
        }
    printf("%lld",ans*4+4);
    return 0;
}

 

posted @ 2017-03-01 20:51  FallDream  阅读(189)  评论(0编辑  收藏  举报