0
点赞
收藏
分享

微信扫一扫

HDU 6434 Problem I. Count


#include<bits/stdc++.h>
using namespace std;
#define LL long long

const int N = 2e7;
const int maxn = N+10;

int T,n;
int primes,prime[maxn],phi[maxn];
bool vis[maxn];
LL ans[maxn];

void init()
{
int i,j;
phi[1]=1;
for (i=2;i<=N;i++)
{
if (!vis[i])
{
prime[++primes]=i;
phi[i]=i-1;
}
for (j=1;j<=primes&&i*prime[j]<=N;j++)
{
vis[i*prime[j]]=1;
if (i%prime[j])
phi[i*prime[j]]=phi[i]*(prime[j]-1);
else
{
phi[i*prime[j]]=phi[i]*prime[j];
break;
}
}
}
phi[1] = 0;
ans[0] = 0;
for (int i = 1; i <= N; i++) {
if (i & 1) {
ans[i] = ans[i-1] + phi[i]/2;
}
else {
ans[i] = ans[i-1] + phi[i];
}
}
}

int main()
{
init();
scanf("%d",&T);
while (T--)
scanf("%d",&n),printf("%lld\n", ans[n]);
}

 

举报

相关推荐

0 条评论