zoukankan      html  css  js  c++  java
  • bzoj 1041: [HAOI2008]圆上的整点 数学

    1041: [HAOI2008]圆上的整点

    Time Limit: 20 Sec

    Memory Limit: 256 MB

    题目连接

    http://www.lydsy.com/JudgeOnline/problem.php?id=1041

    Description

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

    Input

    r

    Output

    整点个数

    Sample Input

    4

    Sample Output

    4

    HINT

     n<=2000 000 000

    题意

    题解:

    http://hzwer.com/1457.html

    代码:

    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <set>
    #include <vector>
    #include <sstream>
    #include <queue>
    #include <typeinfo>
    #include <fstream>
    #include <map>
    #include <stack>
    typedef long long ll;
    using namespace std;
    //freopen("D.in","r",stdin);
    //freopen("D.out","w",stdout);
    #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
    #define test freopen("test.txt","r",stdin)  
    #define maxn 2000001
    #define mod 10007
    #define eps 1e-9
    const int inf=0x3f3f3f3f;
    const ll infll = 0x3f3f3f3f3f3f3f3fLL;
    inline 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,ans;
    ll gcd(ll a,ll b)
    {
        return b==0?a:gcd(b,a%b);
    }
    int 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 1;
        }
        return 0;
    }
     
    int main()
    {
        r=read();
        for(ll i=1;i<=sqrt(2*r);i++)
        {
            if((2*r)%i==0)
            {
                for(ll a=1;a<=sqrt(r/i);a++)
                {
                    double b=sqrt(((2*r)/i)-a*a);
                    if(check(a,b))
                        ans++;
                }
                if(i!=(2*r)/i)
                {
                    for(ll a=1;a<=sqrt(i/2);a++)
                    {
                        double b=sqrt(i-a*a);
                        if(check(a,b))
                            ans++;
                    }
                     
                }
            }
        }
        cout<<ans*4+4<<endl;
    }
  • 相关阅读:
    QDUOJ LC的课后辅导 单调递增栈
    蓝桥杯 时间问题
    区间sum 和为k的连续区间-前缀和
    康托展开-全排列的编码与解码
    康托展开-全排列应用
    背包之01背包、完全背包、多重背包详解
    HDU
    辗转相除求最大公约数与最小公倍数
    快速幂(反复平方法)
    HDU
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4580484.html
Copyright © 2011-2022 走看看