【bzoj2818】: Gcd 数论-欧拉函数
2024-10-21 14:31:40
考虑素数p<=n
gcd(xp,yp)=p 当 gcd(x,y)=1 xp,yp<=n满足条件
p对答案的贡献:
预处理前缀和就好了
/* http://www.cnblogs.com/karl07/ */
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std; #define ll long long
const int N=1e7+;
ll phi[N],prime[N];
int cnt=,n;
ll ans; void PHI(int n){
phi[]=;
for (int i=;i<=n;i++){
if (!phi[i]){
prime[++cnt]=i;
for (int j=i;j<=n;j+=i){
if (phi[j]==) phi[j]=j;
phi[j]=phi[j]/i*(i-);
}
}
}
} int main(){
scanf("%d",&n);
PHI(n);
for (int i=;i<=n;i++) phi[i]+=phi[i-];
for (int i=;i<=cnt;i++){
ans+=phi[n/prime[i]]*-;
}
printf("%lld\n",ans);
return ;
}
最新文章
- jdk安装和环境变量配置
- JS事件冒泡
- 配置nginx,支持php的pathinfo路径模式
- wordpress高级教程
- VsVim的快捷键使用
- Android复习--广播
- 从零开始理解JAVA事件处理机制(3)
- MATLAB中最基本函数plot()的用法
- 学习资料分享:Python能做什么?
- pycharm的用法
- vue---条件与循环语句
- oracle显示一个月的所有天数
- Java_IO异常处理方式_入门小笔记
- NOIP2016 D2-T3 愤怒的小鸟
- Go Example--限速
- Eclipse工程文件夹 红叹号
- CF271D_Good Substrings
- PHP ImageMagick
- Monitorix:一款面向Linux的轻型系统和网络监测工具
- js获取url链接地址的参数
热门文章
- Cache-Control头
- [转]ubuntu11.04配置nfs--解决mount.nfs: access denied问题
- Swing编程练习。可能这篇会有错误哦
- 往jdk/bin目录中增加tcnative-1.dll文件以后报错 Can&#39;t load AMD 64-bit .dll on a IA 32-bit platform
- 深入浅出 消息队列 ActiveMQ------增强版
- PHP函数(六)-匿名函数(闭包函数)
- Python函数(八)-装饰器(一)
- Python多进程-进程锁
- spirngmvc整合mybatis实现CRUD
- MySQL存储引擎 -- MyISAM(表锁定) 与 InnoDB(行锁定) 锁定机制