The Preliminary Contest for ICPC Asia Nanjing 2019 C. Tsy's number 5

https://nanti.jisuanke.com/t/41300
题意:求\(\sum_{i=1}^n\phi(i)\phi(j)2^{\phi(i)\phi(j)}\)
\(f_i=\sum_{k=1}^n[\phi(k)==i]\)
\(\sum_{i=1}^n\phi(i)\phi(j)2^{\phi(i)\phi(j)}\)
\(=\sum_{i=1}^n\sum_{j=1}^nf_if_jij2^{ij}\)
\(=2\sum_{i=1}^n\sum_{j=1}^if_if_jij2^{ij}-\sum_{i=1}^nf_ii2^{i^2}\)
\(=2\sum_{i=1}^nif_i\sum_{j=1}^ijf_j2^{i^2+j^2-(i-j)^2}-\sum_{i=1}^nf_ii2^{i^2}\)
\(=2\sum_{i=1}^nif_i{\sqrt 2}^{i^2}\sum_{j=1}^ijf_j{\sqrt 2}^{j^2}{\sqrt 2}^{-(i-j)^2}-\sum_{i=1}^nf_ii2^{i^2}\)
后一个\(\sum\)ntt,预处理f,\(\sqrt2\)的二次剩余

//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
//#pragma GCC optimize(4)
//#pragma GCC optimize("unroll-loops")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
//#include <bits/extc++.h>
#define fi first
#define se second
#define db double
#define mp make_pair
#define pb push_back
#define mt make_tuple
#define pi acos(-1.0)
#define ll long long
#define vi vector<int>
#define mod 998244353
#define ld long double
//#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
#define ull unsigned long long
#define bpc __builtin_popcount
#define base 1000000000000000000ll
#define fin freopen("1.in","r",stdin)
#define fout freopen("a.txt","w",stdout)
#define fio ios::sync_with_stdio(false);cin.tie(0)
#define mr mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
template<typename T>inline T const& MAX(T const &a,T const &b){return a>b?a:b;}
template<typename T>inline T const& MIN(T const &a,T const &b){return a<b?a:b;}
inline ll mul(ll a,ll b,ll c){return (a*b-(ll)((ld)a*b/c)*c+c)%c;}
inline ll qp(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
inline ll qp(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=mul(ans,a,c);a=mul(a,a,c),b>>=1;}return ans;}

using namespace std;
//using namespace __gnu_pbds;

const ull ba=233;
const db eps=1e-5;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int N=100000+10,maxn=2000000+10,inf=0x3f3f3f3f;

int prime[N],cnt,phi[N],f[N];
bool mark[N];
void init()
{
    phi[1]=1;
    for(int i=2;i<N;i++)
    {
        if(!mark[i])prime[++cnt]=i,phi[i]=i-1;
        for(int j=1;j<=cnt&&i*prime[j]<N;j++)
        {
            mark[i*prime[j]]=1;
            if(i%prime[j]==0)
            {
                phi[i*prime[j]]=phi[i]*prime[j];
                break;
            }
            phi[i*prime[j]]=phi[i]*phi[prime[j]];
        }
    }
}
ll x[N<<3],y[N<<3];
int rev[N<<3];
void getrev(int bit)
{
    for(int i=0;i<(1<<bit);i++)
        rev[i]=(rev[i>>1]>>1) | ((i&1)<<(bit-1));
}
void ntt(ll *a,int n,int dft)
{
    for(int i=0;i<n;i++)
        if(i<rev[i])
            swap(a[i],a[rev[i]]);
    for(int step=1;step<n;step<<=1)
    {
        ll wn=qp(3,(mod-1)/(step*2));
        if(dft==-1)wn=qp(wn,mod-2);
        for(int j=0;j<n;j+=step<<1)
        {
            ll wnk=1;
            for(int k=j;k<j+step;k++)
            {
                ll x=a[k];
                ll y=wnk*a[k+step]%mod;
                a[k]=(x+y)%mod;a[k+step]=(x-y+mod)%mod;
                wnk=wnk*wn%mod;
            }
        }
    }
    if(dft==-1)
    {
        ll inv=qp(n,mod-2);
        for(int i=0;i<n;i++)a[i]=a[i]*inv%mod;
    }
}
int main()
{
    ll ty=116195171ll;
    init();
    int T;scanf("%d",&T);
    while(T--)
    {
        int n;scanf("%d",&n);
        memset(f,0,sizeof f);
        for(int i=1;i<=n;i++)f[phi[i]]++;
        int sz=0,len;
        while((1<<sz)<=n)sz++;sz++;
        len=(1<<sz);
        getrev(sz);
        x[0]=0;y[0]=1;
        for(int i=1;i<=n;i++)
        {
            ll te=qp(ty,1ll*i*i);
            x[i]=1ll*i*f[i]%mod*te%mod;
            y[i]=qp(te,mod-2);
        }
        for(int i=n+1;i<len;i++)x[i]=y[i]=0;
        ntt(x,len,1);ntt(y,len,1);
        for(int i=0;i<len;i++)x[i]=x[i]*y[i]%mod;
        ntt(x,len,-1);
        ll ans=0;
        for(int i=1;i<=n;i++)
        {
            add(ans,2ll*i*f[i]%mod*qp(ty,1ll*i*i)%mod*x[i]%mod);
            sub(ans,1ll*f[i]*f[i]%mod*i%mod*i%mod*qp(2,1ll*i*i)%mod);
        }
        printf("%lld\n",ans);
    }
    return 0;
}
/********************

********************/
posted @ 2019-09-02 14:36  walfy  阅读(233)  评论(0编辑  收藏  举报