Bzoj4805: 欧拉函数求和
好久没写杜教筛了
练练手AC量刷起
# include <bits/stdc++.h>
# define RG register
# define IL inline
# define Fill(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef long long ll;
const int _(1e7 + 1);
IL int Input(){
RG int x = 0, z = 1; RG char c = getchar();
for(; c < '0' || c > '9'; c = getchar()) z = c == '-' ? -1 : 1;
for(; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
return x * z;
}
int prime[_], num, n, tot;
ll phi[_];
map <ll, ll> Phi;
bool isprime[_];
IL void Sieve(RG int m){
isprime[1] = 1, phi[1] = 1, tot = m;
for(RG int i = 2; i <= m; ++i){
if(!isprime[i]) prime[++num] = i, phi[i] = i - 1;
for(RG int j = 1; j <= num && i * prime[j] <= m; ++j){
isprime[i * prime[j]] = 1;
if(i % prime[j]) phi[i * prime[j]] = phi[i] * (prime[j] - 1);
else{
phi[i * prime[j]] = phi[i] * prime[j];
break;
}
}
}
for(RG int i = 2; i <= m; ++i) phi[i] += phi[i - 1];
}
IL ll S(RG ll x){
return x * (x + 1) >> 1;
}
IL ll Du_Sieve(RG ll m){
if(m <= tot) return phi[m];
if(Phi[m]) return Phi[m];
RG ll ret = m * (m + 1) >> 1;
for(RG int i = 2, j; i <= m; i = j + 1){
j = m / (m / i);
ret -= 1LL * (j - i + 1) * Du_Sieve(m / i);
}
return Phi[m] = ret;
}
int main(RG int argc, RG char* argv[]){
n = Input();
Sieve(pow(n, 2.0 / 3.0));
printf("%lld\n", Du_Sieve(n));
return 0;
}
Bzoj4805: 欧拉函数求和的更多相关文章
- BZOJ4805: 欧拉函数求和(杜教筛)
4805: 欧拉函数求和 Time Limit: 15 Sec Memory Limit: 256 MBSubmit: 614 Solved: 342[Submit][Status][Discus ...
- 【BZOJ4805】欧拉函数求和(杜教筛)
[BZOJ4805]欧拉函数求和(杜教筛) 题面 BZOJ 题解 好久没写过了 正好看见了顺手切一下 令\[S(n)=\sum_{i=1}^n\varphi(i)\] 设存在的某个积性函数\(g(x) ...
- poj3090欧拉函数求和
E - (例题)欧拉函数求和 Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:65536KB ...
- 【bzoj3944/bzoj4805】Sum/欧拉函数求和 杜教筛
bzoj3944 题目描述 输入 一共T+1行 第1行为数据组数T(T<=10) 第2~T+1行每行一个非负整数N,代表一组询问 输出 一共T行,每行两个用空格分隔的数ans1,ans2 样例输 ...
- HDU2824-The Euler function-筛选法求欧拉函数+求和
欧拉函数: φ(n)=n*(1-1/p1)(1-1/p2)....(1-1/pk),其中p1.p2-pk为n的所有素因子.比如:φ(12)=12*(1-1/2)(1-1/3)=4.可以用类似求素数的筛 ...
- [BZOJ]4805: 欧拉函数求和
解题思路类似莫比乌斯函数之和 题目大意:求[1,n]内的欧拉函数$\varphi$之和.($n<=2*10^{9}$) 思路:令$ M(n)=\sum_{i=1}^{n}\varphi (i) ...
- 【BZOJ4805】欧拉函数求和
题面 Description 给出一个数字N,求\(\sum\limits_{i=1}^n\varphi(i)\)i,1<=i<=N Input 正整数N.N<=2*10^9 Out ...
- BZOJ 4805: 欧拉函数求和 杜教筛
https://www.lydsy.com/JudgeOnline/problem.php?id=4805 给出一个数字N,求sigma(phi(i)),1<=i<=N https://b ...
- 【BZOJ3944/4805】Sum/欧拉函数求和 杜教筛
[BZOJ3944]Sum Description Input 一共T+1行 第1行为数据组数T(T<=10) 第2~T+1行每行一个非负整数N,代表一组询问 Output 一共T行,每行两个用 ...
随机推荐
- Maven下的SpringMVC MyBatis
从头开始采用Maven管理,Spring.MyBatis.Tomcat. 在配置过程中SQL Server的Jar老是加载不了,解决方案参考前一篇博文. eclipse中已经自带了Maven的插件所以 ...
- Python构建发布
click python配置apache的web服务器方法(python的CGI配置) python中的编码问题 http://blog.csdn.net/wyb_hardworking/articl ...
- Gitbucket—快速建立自己的Github
GitBucket是一个用Scala语言编写的类似Github的应用,界面非常相似.它非常容易安装–容易到你只需要把它的war文件扔到tomcat中,然后启动tomcat就直接可以访问了.或者直接ja ...
- abp允许跨域代码,时间转换为固定格式,本地时间
在Global的 Application_BeginRequest方法中: Thread.CurrentThread.CurrentCulture = new CultureInfo("z ...
- Mysql给某一台主机授权访问,修改root密码
ubuntu上用的是phpstudy,安装好之后,敲mysql,提示没有,需要安装mysql的客户端. 安装好之后直接敲mysql,敲 mysql 再敲use mysql 再敲mysql -uroot ...
- 批标准化(Batch Norm)
BN作用: 加速收敛 控制过拟合,可以少用或不用Dropout和正则 降低网络对初始化权重不敏感 允许使用较大的学习率 一.如何加速收敛? 通过归一化输入值/隐藏单元值,以获得类似的范围值,可加速学习 ...
- qt Multimedia 模块类如何使用?
qt 多媒体模块介绍 类名 英文描述 中文描述 QAudioBuffer Represents a collection of audio samples with a specific format ...
- 谈一谈Java中的Error和Exception
Error和Exception的联系 继承结构:Error和Exception都是继承于Throwable,RuntimeException继承自Exception. Error和RuntimeExc ...
- Docker系统七:Docker数据管理
Docker的数据管理 I. 基本概念 Docker容器一旦删除,其相关的rootf文件系统就会被删除,其容器内的数据将一并删除,为了保存相关数据,Docker提出了数据卷的概念. II. 数据卷 D ...
- Centos安装jdk8
1.下载jdk1.8的tar cd /usr/local/src #切换到该目录下 wget url #下载jdk8的tar包 2.下载完成后解压tar包 tar -zxvf jdk-8u152-li ...