ACM-ICPC 2018 Nanjing Division Network Preliminaries J. Sum

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=ab and 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=1n​f(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=1n​f(i).

Hint

\sum_{i = 1}^8 f(i)=f(1)+ \cdots +f(8)∑i=18​f(i)=f(1)+⋯+f(8) =1+2+2+1+2+4+2+0=14=1+2+2+1+2+4+2+0=14.

样样输入plication

2
5
8

样样出副本

8
14

题来源

思维: The number of the same factor is not more than 2 Squarefree (SF), F [i] = the number of A*B, AB is SF, AB and AB are two programs when AB is not equal, and find the prefix of F[i] in 1~n.

魔改linear screen, too 6, Orz..................

码:

#include<bits/stdc++.h >
Using namespace std;
Const int maxn=2e7+5;
Long long ans[maxn];
Int tot, prime[maxn], vis[maxn],f[maxn];///prime holds the prime number traversed

Void doit(){
    Memset(vis,0,sizeof(vis));
    Memset(prime,0,sizeof(prime));
    Memset(f,0,sizeof(f));

    Prime[1]=1;
    Ans[1]=1;
    Tot=0;

    For(int i=2;i<maxn;i++){
        If(!vis[i]){
            Prime[tot++]=i;
            f[i]=2;
        }

        For(int j=0;j<tot&&i*prime[j]<maxn;j++){
            Vis[i*prime[j]]=1;
            If(i%prime[j]==0){
                If(i%(prime[j]*prime[j])==0) f[i*prime[j]]=0;/// is greater than or equal to cubic GG
                Else f[i*prime[j]]=f[i]/2;/// is equal to half of the quadratic, which is quite less than the original prime
                Break;
            }
            Else f[prime[j]*i]=f[i]*2;
        }
        Ans[i]=ans[i-1]+f[i];
    }
}



Int main(){
    Doit();

    Int t;
    Scanf("%d",&t);
    While(t--){
        Int n;
        Scanf("%d",&n);
        Printf("%lld\n",ans[n]);
    }
}