Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
好久没有刷题了!半天才ac!其实就是欧拉函数的模板题目!哎!!!#include <stdio.h> #include <stdlib.h> #define N 1000000 int prime[N + 1]; __int64 ans[N + 1]; int main() { int i, j, n; prime[0] = prime[1] = 0; for (i=2; i<=N; i++) prime[i] = 1; for (i=2; i*i<=N; i++) { if (prime[i]) { for (j=i*i; j<=N; j+=i) prime[j] = 0; } } for (i=1; i<=N; i++) ans[i] = i; for (i=2; i<=N; i++) { if (prime[i]) { for (j=i; j<=N; j+=i) ans[j] = ans[j] / i * (i - 1); } } for (i=3; i<=N; i++) ans[i] += ans[i - 1]; while(scanf("%d",&n)!=EOF&&n) printf("%I64d\n", ans[n]); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator