BZOJ 3944 Sum
题目链接:Sum
嗯……不要在意……我发这篇博客只是为了保存一下杜教筛的板子的……
你说你不会杜教筛?唐老师(其实我不认识)写了一篇讲的非常好的博客,看完应该就会了……
这道题就是杜教筛板子题,也没什么好讲的……
下面贴代码(不知道为什么我的常数就是大):
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define File(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
#define maxn 5664511 using namespace std;
typedef long long llg; int pr[maxn],T,n,lp;
bool vis[maxn],vu[1300],vp[1300];
llg mu[maxn],phi[maxn],su[1300],sp[1300]; void pre(){
mu[1]=phi[1]=1;
for(int i=2;i<maxn;i++){
if(!vis[i]) pr[++lp]=i,mu[i]=-1,phi[i]=i-1;
for(int j=1;j<=lp && pr[j]*i<maxn;j++){
vis[i*pr[j]]=1;
if(i%pr[j]!=0) mu[i*pr[j]]=-mu[i],phi[i*pr[j]]=phi[i]*phi[pr[j]];
else{phi[i*pr[j]]=phi[i]*pr[j];break;}
}
}
for(int i=2;i<maxn;i++) mu[i]+=mu[i-1],phi[i]+=phi[i-1];
} llg solveu(int x){
if(x<maxn) return mu[x];
if(vu[n/x]) return su[n/x];
llg now=1; vu[n/x]=1;
for(int i=2,nt=0;nt<x;i=nt+1) nt=x/(x/i),now-=(nt-i+1)*solveu(x/i);
return su[n/x]=now;
} llg solvep(llg x){
if(x<maxn) return phi[x];
if(vp[n/x]) return sp[n/x];
llg now=x*(llg)(x+1); now>>=1;
for(int i=2,nt=0;nt<x;i=nt+1) nt=x/(x/i),now-=(nt-i+1)*solvep(x/i);
vp[n/x]=1; return sp[n/x]=now;
} int main(){
File("a");
scanf("%d",&T); pre();
while(T--){
scanf("%d",&n);
memset(vu,0,sizeof(vu));
memset(vp,0,sizeof(vp));
printf("%lld %lld\n",solvep(n),solveu(n));
}
return 0;
}
BZOJ 3944 Sum的更多相关文章
- ●杜教筛入门(BZOJ 3944 Sum)
入门杜教筛啦. http://blog.csdn.net/skywalkert/article/details/50500009(好文!) 可以在$O(N^{\frac{2}{3}})或O(N^{\f ...
- BZOJ 3944: Sum [杜教筛]
3944: Sum 贴模板 总结见学习笔记(现在还没写23333) #include <iostream> #include <cstdio> #include <cst ...
- bzoj 3944: Sum(杜教筛)
3944: Sum Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 4930 Solved: 1313[Submit][Status][Discuss ...
- BZOJ.3944.Sum(Min_25筛)
BZOJ 洛谷 不得不再次吐槽洛谷数据好水(连\(n=0,2^{31}-1\)都没有). \(Description\) 给定\(n\),分别求\[\sum_{i=1}^n\varphi(i),\qu ...
- bzoj 3944 Sum —— 杜教筛
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3944 杜教筛入门题! 看博客:https://www.cnblogs.com/zjp-sha ...
- BZOJ 3944 Sum 解题报告
我们考虑令: \[F_n = \sum_{d|n}\varphi(d)\] 那么,有: \[\sum_{i=1}^{n}F_i = \sum_{i=1}^{n}\sum_{d|i}\varphi(d) ...
- 【刷题】BZOJ 3944 Sum
Description Input 一共T+1行 第1行为数据组数T(T<=10) 第2~T+1行每行一个非负整数N,代表一组询问 Output 一共T行,每行两个用空格分隔的数ans1,ans ...
- 「bzoj 3944: Sum」
题目 杜教筛板子了 #include<iostream> #include<cstring> #include<cstdio> #include<cmath& ...
- bzoj 3944: Sum【莫比乌斯函数+欧拉函数+杜教筛】
一道杜教筛的板子题. 两个都是积性函数,所以做法是一样的.以mu为例,设\( f(n)=\sum_{d|n}\mu(d) g(n)=\sum_{i=1}^{n}f(i) s(n)=\sum_{i=1} ...
随机推荐
- Linux发邮件之mail命令
一.mail命令 1.配置 vim /etc/mail.rc 文件尾增加以下内容 set from=1968089885@qq.com smtp="smtp.qq.com" set ...
- 5.在MVC中使用泛型仓储模式和工作单元来进行增删查改
原文链接:http://www.c-sharpcorner.com/UploadFile/3d39b4/crud-operations-using-the-generic-repository-pat ...
- javascript编程杂记
1.数组深复制 var obj =[1,2,4]: var obj2 = obj.slice(0);
- LCM性质 + 组合数 - HDU 5407 CRB and Candies
CRB and Candies Problem's Link Mean: 给定一个数n,求LCM(C(n,0),C(n,1),C(n,2)...C(n,n))的值,(n<=1e6). analy ...
- react-native的tabbar和navigator混合使用
前段时间搭建项目使用了navigator和react-native-tab-navigator,现在我教大家搭建一个通用的简单框架. 先把几张图贴在这里,这就是我们今天要搭建的东西,别看页面简单,但是 ...
- JavaScript原型OOP——你上车了吗?
.title-bar { width: 80%; height: 35px; padding-left: 35px; color: white; line-height: 35px; font-siz ...
- mongo DB for C#
(1)Download the MongoDB C#驱动. http://www.nuget.org/packages/mongocsharpdriver/. (2) Add Reference to ...
- 【手记】为windows2008建个睡眠快捷方式
----------------201607041343更新---------------- 在另一台电脑上SetSystemPowerState又不好使了,执行了根本没反应.又回头来试SetSusp ...
- 【无私分享:ASP.NET CORE 项目实战(第十二章)】添加对SqlServer、MySql、Oracle的支持
目录索引 [无私分享:ASP.NET CORE 项目实战]目录索引 简介 增加对多数据库的支持,并不是意味着同时对多种数据库操作,当然,后面,我们会尝试同时对多种数据库操作,这可能需要多个上下文,暂且 ...
- Web Service概念梳理
计算机技术难理解的很多,Web Service 对我来说就是一个很难理解的概念:为了弄清它到底是什么,我花费了两周的时间,总算有了一些收获,参考了不少网上的资料,但有些概念说法不一.我以w3c和 一些 ...