Bzoj 1041 haoi2008 round vertices Number Theory

Source: Internet
Author: User



于是去找了下题解,发现这样一种方法:(原帖地址: )


化简为 y^2=(r-x)(r+x)








枚举2r的因数d,对于每个d我们用O[√(r/d)]的时间枚举u 代入r的计算式得出v^2 计算v^2是否为完全平衡数及u与v是否互质

这样可以枚举出一个象限内的整点个数 然后输出(ans+1)*4即可

#include<cmath>#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;typedef long long ll;ll r,ans;ll factors[100100];int tot;void Get_Factors(ll x){ll i;for(i=1;i*i<x;i++)if(x%i==0)factors[++tot]=i,factors[++tot]=x/i;if(i*i==x)factors[++tot]=i;}ll GCD(ll x,ll y){return y?GCD(y,x%y):x;}bool Is_Square(ll x){double temp=sqrt( (double)x );if(fabs(floor(temp+1e-7)-temp)<1e-7)return true;return false;}int main(){cin>>r;int i;ll u;Get_Factors(r<<1);for(i=1;i<=tot;i++){ll d=factors[i];for(u=1;u*u<(r+1)/d;u++){ll v_2=r*2/factors[i]-u*u;if( Is_Square(v_2) )if(GCD(v_2,u*u)==1)++ans;}}cout<<(ans+1<<2)<<endl;}

BZOJ 1041 HAOI2008 圆上的整点 数论

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.