BZOJ 1041: [HAOI2008]圆上的整点

Sol

数学.

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

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

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

令 \(d=(r-x,r+x)\)

\(r-x=du^2,r+x=dv^2\)

\(2r=d(u^2+v^2),(v,u)==1\)

\(y^2=d^2u^2v^2\)

然后枚举 \(d\) 再枚举 \(u\)

Code

/**************************************************************
    Problem: 1041
    User: BeiYu
    Language: C++
    Result: Accepted
    Time:80 ms
    Memory:1300 kb
****************************************************************/
 
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
using namespace std;
  
typedef long long LL;
  
LL r,n,ans;
  
inline LL in(LL x=0,char ch=getchar()){ while(ch>'9'||ch<'0') ch=getchar();
    while(ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=getchar();return x; } 
  
LL calc(LL d){
    LL res=0,m=n/d;
    for(LL u=1,v;2*u*u<=m;u++){
        v=sqrt(m-u*u)+0.5;
        if(v<=u) break;
        if(v*v+u*u==m&&__gcd(u,v)==1) res++;
    }return res;
}
int main(){
//  freopen("in.in","r",stdin);
    r=in(),n=r<<1;
    for(LL d=1;d*d<=n;d++) if(n%d==0){
        if(d*d==n) ans+=calc(d);
        else ans+=calc(d)+calc(n/d);
    }
    cout<<ans*4+4<<endl;
    return 0;
}

  

转载于:https://www.cnblogs.com/beiyuoi/p/5854376.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值