A square-free integer is an integer which is indivisible by any square number except 11. For example, 6 = 2 \cdot 36=2⋅3 is square-free, but 12 = 2^2 \cdot 312=22⋅3 is not, because 2^222 is a square number. Some integers could be decomposed into product of two square-free integers, there may be more than one decomposition ways. For example, 6 = 1\cdot 6=6 \cdot 1=2\cdot 3=3\cdot 2, n=ab6=1⋅6=6⋅1=2⋅3=3⋅2,n=aband n=ban=ba are considered different if a \not = ba̸=b. f(n)f(n) is the number of decomposition ways that n=abn=ab such that aa and bb are square-free integers. The problem is calculating \sum_{i = 1}^nf(i)∑i=1nf(i).
Input
The first line contains an integer T(T\le 20)T(T≤20), denoting the number of test cases.
For each test case, there first line has a integer n(n \le 2\cdot 10^7)n(n≤2⋅107).
Output
For each test case, print the answer \sum_{i = 1}^n f(i)∑i=1nf(i).
Hint
\sum_{i = 1}^8 f(i)=f(1)+ \cdots +f(8)∑i=18f(i)=f(1)+⋯+f(8)
=1+2+2+1+2+4+2+0=14=1+2+2+1+2+4+2+0=14.
样例输入复制
2
5
8
样例输出复制
8
14
题目来源
#include<bits/stdc++.h>
using namespace std;
const int N=20000007;
int vis[N+5],prime[N+5],ans[N+5],f[N+5];
void init()
{
vis[1]=1;
f[1]=1;
int cnt=0;
for(int i=2;i<=N;i++)
{
if(!vis[i])
{
prime[++cnt]=i;
f[i]=2;
}
for(int j=1;j<=cnt&&i*prime[j]<N;j++)
{
int tmp=i*prime[j];
vis[tmp]=1;
if(i%prime[j])
f[tmp]=f[i]*2;
else if(i%(prime[j]*prime[j])==0)
f[tmp]=0;
else
{
f[tmp]=f[tmp/prime[j]/prime[j]];
break;
}
}
}
for(int i=1;i<=N;i++)
ans[i]=ans[i-1]+f[i];
}
int main()
{
init();
int t,n;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
printf("%d\n",ans[n]);
}
return 0;
}