Code:

#include<cstdio>
using namespace std;
const int maxn=4000005;
const int R=4000002;
const int N=4000002;
long long sumv[maxn],f[maxn];
int phi[maxn],prime[maxn],vis[maxn];
void solve(){
phi[1]=1;
int cnt=0;
for(int i=2;i<=R;++i){
if(!vis[i])prime[++cnt]=i,phi[i]=i-1;
for(int j=1;j<=cnt&&prime[j]*i<=R;++j){
vis[prime[j]*i]=1;
if(i%prime[j]!=0)phi[i*prime[j]]=phi[i]*(prime[j]-1);
else{
phi[i*prime[j]]=phi[i]*prime[j];
break;
}
}
}
for(int i=1;i<N;++i)
for(int j=i*2;j<N;j+=i)
f[j]+=i*phi[j/i];
for(int i=1;i<N;++i)
sumv[i]=sumv[i-1]+f[i];
}
int main(){
solve();
while(1){
int n;scanf("%d",&n);
if(!n)break;
printf("%lld\n",sumv[n]);
}
return 0;
}

GCD - Extreme (II) UVA - 11426 欧拉函数_数学推导的更多相关文章

  1. GCD - Extreme (II) UVA - 11426 欧拉函数与gcd

    题目大意: 累加从1到n,任意两个数的gcd(i,j)(1=<i<n&&i<j<=n). 题解:假设a<b,如果gcd(a,b)=c.则gcd(a/c,b ...

  2. UVa 11426 (欧拉函数 GCD之和) GCD - Extreme (II)

    题意: 求sum{gcd(i, j) | 1 ≤ i < j ≤ n} 分析: 有这样一个很有用的结论:gcd(x, n) = i的充要条件是gcd(x/i, n/i) = 1,因此满足条件的x ...

  3. GCD - Extreme (II) UVA - 11426(欧拉函数!!)

    G(i) = (gcd(1, i) + gcd(2, i) + gcd(3, i) + .....+ gcd(i-1, i)) ret = G(1) + G(2) + G(3) +.....+ G(n ...

  4. UVA 11426 (欧拉函数&&递推)

    题意:给你一个数N,求N以内和N的最大公约数的和 解题思路: 一开始直接想暴力做,4000000的数据量肯定超时.之后学习了一些新的操作. 题目中所要我们求的是N内gcd之和,设s[n]=s[n-1] ...

  5. UVA - 11426 欧拉函数(欧拉函数表)

    题意: 给一个数 N ,求 N 范围内所有任意两个数的最大公约数的和. 思路: f 数组存的是第 n 项的 1~n-1 与 n 的gcd的和,sum数组存的是 f 数组的前缀和. sum[n]=f[1 ...

  6. GCD - Extreme (II) UVA - 11426 数学

    Given the value of N , you will have to nd the value of G . The de nition of G is given below: G = i ...

  7. F - GCD - Extreme (II) UVA - 11426

    Given the value of N, you will have to find the value of G. The definition of G is given below:

  8. HDU5780 gcd (BestCoder Round #85 E) 欧拉函数预处理——分块优化

    分析(官方题解): 一点感想: 首先上面那个等式成立,然后就是求枚举gcd算贡献就好了,枚举gcd当时赛场上写了一发O(nlogn)的反演,写完过了样例,想交发现结束了 吐槽自己手速慢,但是发了题解后 ...

  9. 【BZOJ2818】Gcd(莫比乌斯反演,欧拉函数)

    题意:给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的数对(x,y)有多少对 1<=N<=10^7 思路:莫比乌斯反演,同BZOJ2820…… ; ..max]of ...

随机推荐

  1. offscreen-render

    offscreen-render 什么是offscreen-render?offscreen-render涉及的内容比较多,有offscreen-render那就有onscreen render,on ...

  2. CF950B Intercepted Message_双指针法

    本来想直接上权值线段树维护区间最值,不过可以用双指针法,就使问题变得简洁. Code: #include<iostream> using namespace std; const int ...

  3. 执行python manage.py makemigrations时报错TypeError: __init__() missing 1 required positional argument: 'on_delete'

    在执行python manage.py makemigrations时报错: TypeError: __init__() missing 1 required positional argument: ...

  4. 编写高性能的javascript代码(持续更新)

    参考资料: Vanilla JS——世界上最轻量的JavaScript框架(没有之一) http://segmentfault.com/a/1190000000355277 探索高效jQuery的奥秘 ...

  5. NOIP2013 华容道 (棋盘建图+spfa最短路)

    #include <cstdio> #include <algorithm> #include <cstring> #include <queue> # ...

  6. python_购物车程序

    #需求1.启动程序后,让用户输入工资,然后打印商品列表2.允许用户根据商品编号购买商品3.用户选择商品后,检测余额是否够,够就直接扣款,不够就提醒4.可随时退出,退出时,打印已购买商品和余额 #先定义 ...

  7. JavaScript 实现简单的 弹出框关闭框

    JavaScript 实现简单的 弹出框关闭框 知识点: 1.javaScript 添加HTML标签 2.javaScript 添加HTML标签属性 3.javaScript 追加元素 代码献上: & ...

  8. GitHub上传项目,使用desktop(客户端)教程

    GitHub上传项目,使用desktop(客户端)教程  搜索“GitHub上传项目”,能得到很多相关的文章教程,里面讲的都特别麻烦,要弄什么ssh之类的,可算是吓坏了我,使我非常的怀疑为什么GitH ...

  9. Linux下的进程环境

    僵尸进程.孤儿进程.守护进程.进程组.会话.前台进程组.后台进程组 1,僵尸进程 子进程结束,父进程没有明确的答复操作系统内核:已收到子进程结束的消息.此时操作系统内核会一直保存该子进程的部分PCB信 ...

  10. Opencv 使用Rect选取与设置窗口ROI

    本系列文章由 @yhl_leo 出品,转载请注明出处. 文章链接: http://blog.csdn.net/yhl_leo/article/details/50593825 首先看一下Rect对象的 ...