题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=5430
解题思路:
官方题解:
AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll;
const int maxn = 1000005;
ll phi[maxn],n;
void solve(){
memset(phi,0,sizeof(phi));
phi[1] = 1;
for(ll i = 2; i <= maxn-3; i++){
if(!phi[i]){
for(ll j = i; j <= maxn-3; j += i){
if(!phi[j])
phi[j] = j;
phi[j] = phi[j]/i*(i-1);
}
}
}
}
int main(){
int T;
solve();
scanf("%d",&T);
while(T--){
int n;
scanf("%d",&n);
printf("%lld\n",phi[n+1]);
}
}