PE556
考虑推广sum(i in Z){mu^2(i)}的做法.
#include"roundCount.cpp"
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
#include<primesieve.hpp>
namespace GPG{
typedef long long ll;
typedef bool B;
namespace Gauss{
#define opr(x,op) inline x operator op (
#define ret(...) ){return ({__VA_ARGS__;});}
#define AL2(x,y,z) x y,x z
#define vopr(x,op,y,z,...) opr(x,op) AL2(x,y,z) ret(__VA_ARGS__)
#define lbd(x,n) inline x n (
struct GI{
int a,b; // a+bi
GI():a(0),b(0){}
GI(int a,int b=0):a(a),b(b){}
};
lbd(ll,norm)GI a ret(a.a*a.a+a.b*a.b)
vopr(GI,+,a,b,GI(a.a+b.a,a.b+b.b))
vopr(GI,-,a,b,GI(a.a-b.a,a.b-b.b))
vopr(GI,*,a,b,GI(a.a*b.a-a.b*b.b,a.a*b.b+a.b*b.a))
opr(B ,<)AL2(GI,a,b)ret(norm(a)<norm(b))
} using namespace Gauss;
#define maxn 10000011
using namespace std;
char v[maxn];
vector<int> prs;
int ppp[10000010];
int nextPP[10001001];
int main(){
primesieve::generate_primes(10000000,&prs);
for(int i=0,_=prs.size();i<_;++i) v[prs[i]]=1;
for(int i=1,j=3162;i*i<=10000000;++i){
while(j && i*i+j*j>10000000)--j;
if(v[i]&&((i&3)==3))ppp[i*i]++;
for(int k=1;k<=j;++k) if(v[i*i+k*k]) ppp[i*i+k*k]++;
}
for(int i=1,last=0;i<=10000000;++i){
if(ppp[i]) nextPP[last]=i,last=i;
}
return 0;
}
} using namespace GPG;
namespace Combine{
int C[22][22];
inline void init_combine(){
C[0][0]=1;
for(int i=1;i<=20;++i){
C[i][0]=1;
for(int j=1;j<=i;++j) C[i][j]=C[i-1][j]+C[i-1][j-1];
}
}
} using namespace Combine;
#define threshold 100000000000000ll
#define thresholdsqrt 10000000ll
/*
#define threshold 10000ll
#define thresholdsqrt 100ll
*/
inline ll dfs(int now,int nowexp,ll mul,ll tot,int mu){
// printf("%d %d %-4lld %-4lld %-3d\n",now,nowexp,mul,tot,mu);
ll ans=nowexp?tot*mu:0;
if(ans){
ans*=RC(threshold/mul/mul);
// printf("+ RC(%lld)=%lld\n",threshold/mul/mul,RC(threshold/mul/mul));
}
int v=nextPP[now];
if(!v || v*mul>thresholdsqrt) return ans;
ans+=dfs(v,0,mul,tot,mu);
for(int i=1;i<=ppp[v];++i){
mu=-mu;
if(double(mul)*v>double(thresholdsqrt))break;
mul*=v;
if(mul>thresholdsqrt)break;
ans+=dfs(v,i,mul,tot*C[ppp[v]][i],mu);
}
return ans;
}
int main(){
RCCC::init();
GPG::main();
Combine::init_combine();
printf("%lld\n",dfs(0,0,1,1,1)+RC(threshold));
return 0;
}
PE556的更多相关文章
随机推荐
- 兼容IE的写法收集||bug修复
这篇文章实时更新 属于IE的专属写法 其中,S表示Standards Mode即标准模式,Q表示Quirks Mode,即兼容模式 hack 示例 IE6(S) IE6(Q) IE7(S) IE7(Q ...
- 关于linux发行版i386/i686/x86-64/的区别
http://blog.chinaunix.net/uid-20448327-id-172412.html
- centos 7.0 查看所有安装的包
rpm方式安装的包 默认 最小化安装centos 7.0 rpm -qa 查看所有安装的包 [root@localhost ~]# rpm -qa biosdevname-0.5.0-10.el7.x ...
- spring boot入门例子
最近学习spring boot,总结一下入门的的基础知识 1新建maven项目,修改pom.xml <project xmlns="http://maven.apache.org/PO ...
- Java中jsp和Servlet的区别
1 Servlet Servlet是一种服务器端的Java应用程序,具有独立于平台和协议的特性,可以生成动态的Web页面.它担当客户请求(Web浏览器或其他HTTP客户程序)与服务器响应(HTTP服务 ...
- javascript简单的认识下return语句+2015的总结+2016的展望
好久没更新博客了...自从有了mac之后世界变得简单了...日常么,除了研究代码,看别人的代码,写自己的代码.就那样.... 吐槽点:window配个nodejs的环境花了九头牛两只老虎的力气,mac ...
- 深度剖析:如何实现一个 Virtual DOM 算法
本文转载自:https://github.com/livoras/blog/issues/13 目录: 1 前言 2 对前端应用状态管理思考 3 Virtual DOM 算法 4 算法实现 4.1 步 ...
- 根据不同的实体及其ID来获取数据库中的数据
/// <summary> /// 根据不同的实体和其ID来获取信息 /// </summary> /// <typeparam name="T"&g ...
- Excel 使用宏批量修改单元格内指定文字为红字
-> step 1:新建宏,进入编辑,使用如下代码: Sub Ss()Dim c As RangeFor Each c In ActiveSheet.UsedRange i = 1 While ...
- poj.1703.Find them, Catch them(并查集)
Find them, Catch them Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I6 ...