//Place your snippets for cpp here. Each snippet is defined under a snippet name and has a prefix, body and 
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the 
// same ids are connected.
// prefix 的格式要求是 acm-[一级标题编号].[二级标题编号][该代码片段的英文简称]
// description 的格式要求是 "插入 [该代码片段的中文名]"

{
    "杜教筛": {
        "prefix": "acm-7.1数组记忆化",
        "body": [
            "#include<algorithm>",
            "#include<cstring>",
            "#include<cstdio>",
            "#include<cmath>",
            "#define Re register int",
            "#define LL long long",
            "using namespace std;",
            "const int N23=1664511+3,N13=1303,N=2147483647;",
            "int x,T,cnt,pan[N23],pri[N23],phi[N23],miu[N23];",
            "int TO,vis1[N13],vis2[N13],Smiu[N23],Smiu_[N13];",
            "LL Sphi[N23],Sphi_[N13];",
            "inline void in(Re &x){",
            "\tRe fu=0;x=0;char ch=getchar();",
            "\twhile(ch<'0'||ch>'9')fu|=ch=='-',ch=getchar();",
            "\twhile(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();",
            "\tx=fu?-x:x;",
            "}",
            "inline void get_(Re N){",
            "\tmiu[1]=phi[1]=pan[1]=1;",
            "\tfor(Re i=2;i<=N;++i){",
            "\t\tif(!pan[i])pri[++cnt]=i,miu[i]=-1,phi[i]=i-1;",
            "\t\tfor(Re j=1;j<=cnt&&pri[j]<=N/i;++j){",
            "\t\t\tpan[i*pri[j]]=1;",
            "\t\t\tif(i%pri[j])miu[i*pri[j]]=-miu[i],phi[i*pri[j]]=phi[i]*phi[pri[j]];",
            "\t\t\telse{miu[i*pri[j]]=0,phi[i*pri[j]]=phi[i]*pri[j];break;}",
            "\t\t}",
            "\t}",
            "\tfor(Re i=1;i<=N;++i)Smiu[i]=Smiu[i-1]+miu[i],Sphi[i]=Sphi[i-1]+phi[i];",
            "}",
            "inline LL get_Sphi(Re n){",
            "\tif(n<=TO)return Sphi[n];",
            "\tRe nn=N/n;",
            "\tif(vis1[nn])return Sphi_[nn];",
            "\tLL ans=(LL)n*(n+1)>>1;",
            "\tfor(Re l=2,r;l<=n;l=r+1){",
            "\t\tr=n/(n/l);",
            "\t\tans-=(LL)(r-l+1)*get_Sphi(n/l);",
            "\t}",
            "\tvis1[nn]=1;",
            "\treturn Sphi_[nn]=ans;",
            "}",
            "inline int get_Smiu(Re n){",
            "\tif(n<=TO)return Smiu[n];",
            "\tRe nn=N/n;",
            "\tif(vis2[nn])return Smiu_[nn];",
            "\tRe ans=1;",
            "\tfor(Re l=2,r;l<=n;l=r+1){",
            "\t\tr=n/(n/l);",
            "\t\tans-=(r-l+1)*get_Smiu(n/l);",
            "\t}",
            "\tvis2[nn]=1;",
            "\treturn Smiu_[nn]=ans;",
            "}",
            "int main(){",
            "//\tfreopen(\"123.txt\",\"r\",stdin);",
            "\tin(T),get_(TO=N23-3);",
            "\twhile(T--){",
            "\t\tin(x),printf(\"%lld %d\\n\",get_Sphi(x),get_Smiu(x));",
            "\t\tmemset(vis1,0,sizeof(vis1));",
            "\t\tmemset(vis2,0,sizeof(vis2));",
            "\t}",
            "}",
            ""
        ],
        "description": "插入 杜教筛"
    }
}