uva 11426-欧拉函数
来源:互联网 发布:php连接mysql数据库 编辑:程序博客网 时间:2024/05/22 04:44
Problem J
GCD Extreme (II)
Input: Standard Input
Output: Standard Output
Given the value of N, you will have to find the value of G. The definition of G is given below:
Here GCD(i,j) means the greatest common divisor of integer i and integer j.
For those who have trouble understanding summation notation, the meaning of G is given in the following code:
G=0;
for(i=1;i<N;i++)
for(j=i+1;j<=N;j++)
{
G+=gcd(i,j);
}
/*Here gcd() is a function that finds the greatest common divisor of the two input numbers*/
Input
The input file contains at most 100 lines of inputs. Each line contains an integer N (1<N<4000001). The meaning of N is given in the problem statement. Input is terminated by a line containing a single zero.
Output
For each line of input produce one line of output. This line contains the value of G for the corresponding N. The value of G will fit in a 64-bit signed integer.
Sample Input Output for Sample Input
10
100
200000
0
67
13015
143295493160
代码:
#include<stdio.h>#include<string.h>#define MAXD 4000010const int N = 4000000;typedef long long LL;int phi[MAXD];LL a[MAXD];void prep(){ memset(a, 0, sizeof(a)); for(int i = 1; i <= N; i ++) phi[i] = i; for(int i = 2; i <= N; i ++) { if(phi[i] == i) { for(int j = i; j <= N; j += i) phi[j] = phi[j] / i * (i - 1); } for(int j = 1; j * i <= N; j ++) a[j * i] += j * phi[i]; } for(int i = 1; i <= N; i ++) a[i] += a[i - 1];}int main(){ prep(); int n; while(scanf("%d", &n), n) printf("%lld\n", a[n]); return 0;}
- uva 11426-欧拉函数
- UVA 11426 欧拉函数
- UVA 11426 (欧拉函数)
- uva 11426 欧拉函数
- UVA 11426 欧拉函数 + 递推
- uva 10820 欧拉函数
- uva 11426 - GCD - Extreme (II) 欧拉函数
- UVa 11426 GCD - Extreme (II) / 素数筛选 + 欧拉函数
- UVa 11426 - GCD - Extreme (II) (数学 欧拉函数)
- uva 11424 && 11426 GCD - Extreme(数论:欧拉函数)
- [欧拉函数] uva 11426 GCD - Extreme (II)
- 【欧拉函数】uva 11426 GCD - Extreme (II)
- UVA 11426 GCD Extreme (II) 欧拉函数
- UVA 11426 GCD - Extreme (II) (数论|欧拉函数)
- uva 11426 - GCD - Extreme (II) 欧拉函数
- Uva 11426 - GCD - Extreme (II) 欧拉函数
- UVA 11426 GCD - Extreme (II) (欧拉函数)
- UVA 11426 GCD - Extreme (II)(欧拉函数)
- 琐碎的生活
- pipe、dup、dup2、wait、waitpid、fork函数说明
- contest 1 F
- 程序员人生之路,几点选择
- css-元素水平、竖直居中
- uva 11426-欧拉函数
- 东北大学CSDN俱乐部3月导师见面会
- ContentProvider实例
- 在ABAP中用事务更新数据
- Java学习注意事项
- 液晶电视面板的类型、等级及鉴别方法
- Code Review中的几个提示
- Centos编译boost
- 《窃听风暴》——献给那个时代的所有人