Sol

数学.

跟圆上的整点一样...TA写了个积性函数的算法...以后再说吧...

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

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

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

\(y^2=\frac{1}{3}(r-x)(r+x)\)

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

\(r-x=3du^2,r+x=dv^2\) 这里 \(r-x\) 和 \(r+x\) 并没有什么区别.

\(2r=d(3u^2+v^2)\)

枚举 \(d\) 和 \(u\)

感觉复杂度是\(O(n^{\frac{3}{4}})\)

但是可以跑最大数据的说.

Code

/**************************************************************
Problem: 4544
User: BeiYu
Language: C++
Result: Accepted
Time:8568 ms
Memory:1300 kb
****************************************************************/ #include<cstdio>
#include<cmath>
#include<algorithm>
#include<vector>
#include<utility>
#include<iostream>
using namespace std; typedef long long LL;
#define debug(a) cout<<#a<<"="<<a<<" "
#define mpr(a,b) make_pair(a,b) LL T,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; } vector<pair<LL,LL> > p; LL calc(LL d){
LL res=0,m=n/d;
// cout<<"*************"<<endl;
// debug(m),debug(d);cout<<endl;
for(LL u=1,v;u*u*3<=m;u++){
v=sqrt(m-3*u*u+0.5);
// debug(u),debug(v),debug(3*v*v+u*u),cout<<endl;
// if(u>v) break;
if(v*v+u*u*3==m&&__gcd(v*v,u*u*3)==1) res++;
// cout<<"get!",debug(d*u*u*3),debug(d*v*v),debug(d*u*u*3+d*v*v)<<endl;
// p.push_back(mpr(d*u*u*3,d*v*v));
}return res;
}
int main(){
// freopen("in.in","r",stdin);
for(T=in();T--;){
r=in(),n=r<<1,ans=0;
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+2<<endl;
// sort(p.begin(),p.end());
// for(int i=0;i<p.size();i++) cout<<p[i].first<<" "<<p[i].second<<endl;
}
return 0;
}

  

BZOJ 4544: 椭圆上的整点的更多相关文章

  1. BZOJ 1041 圆上的整点

    题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=1041 题意:求圆x^2+y^2=r^2上的整点. 思路:由于对称性,我们只需要计算第一象 ...

  2. [BZOJ]1045 圆上的整点(HAOI2008)

    数学题第二弹! Description 求一个给定的圆(x^2+y^2=r^2),在圆周上有多少个点的坐标是整数. Input 一个正整数r. Output 整点个数. Sample Input 4 ...

  3. bzoj 1041 圆上的整点 分类: Brush Mode 2014-11-11 20:15 80人阅读 评论(0) 收藏

    这里先只考虑x,y都大于0的情况 如果x^2+y^2=r^2,则(r-x)(r+x)=y*y 令d=gcd(r-x,r+x),r-x=d*u^2,r+x=d*v^2,显然有gcd(u,v)=1且u&l ...

  4. BZOJ 1041 圆上的整点 数学

    题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=1041 题目大意:求一个给定的圆(x^2+y^2=r^2),在圆周上有多少个点的坐标是整 ...

  5. BZOJ4544 椭圆上的整点(数论)

    https://www.cnblogs.com/Gloid/p/9538413.html 基本思路没有太大差别.得到2n=d(a2+3b2),其中d=gcd(n-x,n+x),n-x==a2& ...

  6. bzoj4544 椭圆上的整点

    我会所有推理..... Q1:真的这么暴力的统计答案? Q2:蜜汁统计答案.... Q3:为什么不考虑3在不同的位置的情况

  7. BZOJ 1041: [HAOI2008]圆上的整点

    1041: [HAOI2008]圆上的整点 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 3621  Solved: 1605[Submit][Sta ...

  8. bzoj 1041: [HAOI2008]圆上的整点 数学

    1041: [HAOI2008]圆上的整点 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/ ...

  9. bzoj 1041: [HAOI2008]圆上的整点 本原勾股數組

    1041: [HAOI2008]圆上的整点 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2027  Solved: 853[Submit][Stat ...

随机推荐

  1. Jquery 的事件方法

    1.$(selector).bind(event,data,function,map) //给元素添加一个事件 2.当元素失去焦点时发生 blur 事件,获得焦点时触发focus事件: $(" ...

  2. python中配置文件写法

    import os BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) print(BASE_DIR) USE ...

  3. Mastering C# structs

    http://www.developerfusion.com/article/84519/mastering-structs-in-c/

  4. yum配置文件详解

    yum是什么: Yellow dog Updater, Modified主要功能是更方便的添加/删除/更新RPM包,自动解决包的倚赖性问题,它能便于管理大量系统的更新问题. yum特点:可以同时配置多 ...

  5. JS的splice()方法和slice()方法

    在w3c school中描述如下: 定义和用法splice() 方法用于插入.删除或替换数组的元素.语法arrayObject.splice(index,howmany,element1,....., ...

  6. motto2

    Baby you've done enough that cut your breath.Don't beat yourself up don't need to turn so fast.Somet ...

  7. CF459E Pashmak and Graph (DP?

    Codeforces Round #261 (Div. 2) E - Pashmak and Graph E. Pashmak and Graph time limit per test 1 seco ...

  8. CF451B Sort the Array 水题

    Codeforces Round #258 (Div. 2) Sort the Array B. Sort the Array time limit per test 1 second memory ...

  9. HTML中head头结构

    HTML head 头部分的标签.元素有很多,涉及到浏览器对网页的渲染,SEO等等,而各个浏览器内核以及各个国内浏览器厂商都有些自己的标签元素,这就造成了很多差异性.移动互联网时代,head 头部结构 ...

  10. java 读取pdf、word、Excel文件

    用到的jar: itextpdf-5.5.8.jar   (PDF) poi.jar public class FileUtils { /** * 判断文件是否存在 * * @Title: isExc ...