【bzoj2818】: Gcd

考虑素数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 ;
}

最新文章

  1. jdk安装和环境变量配置
  2. JS事件冒泡
  3. 配置nginx,支持php的pathinfo路径模式
  4. wordpress高级教程
  5. VsVim的快捷键使用
  6. Android复习--广播
  7. 从零开始理解JAVA事件处理机制(3)
  8. MATLAB中最基本函数plot()的用法
  9. 学习资料分享:Python能做什么?
  10. pycharm的用法
  11. vue---条件与循环语句
  12. oracle显示一个月的所有天数
  13. Java_IO异常处理方式_入门小笔记
  14. NOIP2016 D2-T3 愤怒的小鸟
  15. Go Example--限速
  16. Eclipse工程文件夹 红叹号
  17. CF271D_Good Substrings
  18. PHP ImageMagick
  19. Monitorix:一款面向Linux的轻型系统和网络监测工具
  20. js获取url链接地址的参数

热门文章

  1. Cache-Control头
  2. [转]ubuntu11.04配置nfs--解决mount.nfs: access denied问题
  3. Swing编程练习。可能这篇会有错误哦
  4. 往jdk/bin目录中增加tcnative-1.dll文件以后报错 Can&#39;t load AMD 64-bit .dll on a IA 32-bit platform
  5. 深入浅出 消息队列 ActiveMQ------增强版
  6. PHP函数(六)-匿名函数(闭包函数)
  7. Python函数(八)-装饰器(一)
  8. Python多进程-进程锁
  9. spirngmvc整合mybatis实现CRUD
  10. MySQL存储引擎 -- MyISAM(表锁定) 与 InnoDB(行锁定) 锁定机制