POJ 3090 Visible Lattice Points 【欧拉函数】
2011-05-06 11:40
567 查看
题目: http://poj.org/problem?id=3090
题意: 如题, 实质是求给出一个n, 求出ψ(1) + ψ(2) + ψ(3) + ... ψ(n).
ψ(i) 是欧拉函数, 表示在 1..i内是i的质因子的个数.
要求ψ(i), 由 i = p1^(a1)*p2^(a2)*p3(a3)...*pi^(ai)
可推出 ψ(i) = i(1 - 1/p1)(1 - 1/p2)...(1 - 1/pi);
pi表示i的素因子.
代码:
题意: 如题, 实质是求给出一个n, 求出ψ(1) + ψ(2) + ψ(3) + ... ψ(n).
ψ(i) 是欧拉函数, 表示在 1..i内是i的质因子的个数.
要求ψ(i), 由 i = p1^(a1)*p2^(a2)*p3(a3)...*pi^(ai)
可推出 ψ(i) = i(1 - 1/p1)(1 - 1/p2)...(1 - 1/pi);
pi表示i的素因子.
代码:
#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> using namespace std; const int MAX = 1000 + 1; int D[MAX]; void phi_table(int n) { int i, j; memset(D, 0, sizeof(D)); D[1] = 1; for(i = 2; i <= n; ++i) { if(!D[i]) { for(j = i; j <= n; j += i) { if(!D[j]) D[j] = j; D[j] =D[j] / i * (i - 1); } } } D[1] = 3; //printf("2 = %d\n", D[5]); for(i = 2; i <= n; ++i) { D[i] = D[i - 1] + D[i] * 2; } } int main() { phi_table(1000); int N, n, i; scanf("%d", &N); for(i = 1; i <= N; ++i) { scanf("%d", &n); printf("%d %d %d\n", i, n, D ); } return 0; }
相关文章推荐
- POJ 3090 Visible Lattice Points(Farey数列&欧拉函数求和)
- POJ 3090 Visible Lattice Points 欧拉函数
- 数论 - 欧拉函数的运用 --- poj 3090 : Visible Lattice Points
- poj 3090 Visible Lattice Points(数论:筛法打表欧拉函数)
- POJ 3090 Visible Lattice Points(欧拉函数)
- POJ 3090 Visible Lattice Points 欧拉函数
- poj 3090 Visible Lattice Points (欧拉函数)
- POJ 3090 Visible Lattice Points | 其实是欧拉函数
- Poj 3090 Visible Lattice Points(欧拉函数)
- POJ3090_Visible Lattice Points【欧拉函数】
- POJ 3090 Visible Lattice Points (欧拉函数)
- [数论] POJ 3090/HOJ 2416 Visible Lattice Points 欧拉函数
- POJ 3090 Visible Lattice Points 欧拉函数的应用
- POJ 3090 Visible Lattice Points 欧拉函数
- POJ 3090 Visible Lattice Points (欧拉函数)
- POJ 3090 (欧拉函数) Visible Lattice Points
- (Relax 数论1.9)POJ 3090 Visible Lattice Points(欧拉函数的应用:计算前n项欧拉数之和)
- POJ 3090-Visible Lattice Points(筛选法求欧拉函数)
- POJ 2478 Farey Sequence & POJ 3090 Visible Lattice Points (欧拉函数)
- 数论 - 欧拉函数的运用 --- poj 3090 : Visible Lattice Points