UVA10820SendATable

//UVA10820SendATable
#include<cstdio>
#include<cstring>
#include<cmath>
const int maxn = 50000;
int phi[maxn + 5];
long long f[maxn + 5];
void phi_table(int n, int *phi) {
	for(int i = 2; i <= n; i++) phi[i] = 0;
	phi[1] = 1;
	for(int i = 2; i <= n; i++) if(!phi[i])
	    for(int j = i; j <= n; j += i) {//相當於篩法 
	    	if(!phi[j]) phi[j] = j;
	    	phi[j] = phi[j] / i * (i - 1);
		}
} 
int main() {
	phi_table(maxn, phi);
	int n;
	for(int i = 2; i <= maxn; i++) f[i] = f[i - 1] + phi[i];
	while(scanf("%d", &n) == 1 && n) printf("%lld\n", 2 * f[n] + 1);
	return 0;
}
/*
2
5
0
*/

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章