uoj62(莫比乌斯反演)

题目链接

http://uoj.ac/problem/62

题解

需要经过很长的推导。。主要参考 VFK的博客

所以

对上式做莫比乌斯反演,得

再做一次莫比乌斯反演

反演的话,万能的VFK还提供了一个非常好使的代码,如下:

若$\displaystyle f(n)=\sum_{d|n}g(d)$ ,有

1
2
3
4
5
for(int i=1;i<=n;i++)
g[i]=f[i];
for(int i=1;i<=n;i++)
for(int j=i+i;j<=n;j+=i)
g[j]-=g[i];




代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/**
*        ┏┓    ┏┓
*        ┏┛┗━━━━━━━┛┗━━━┓
*        ┃       ┃  
*        ┃   ━    ┃
*        ┃ >   < ┃
*        ┃       ┃
*        ┃... ⌒ ...  ┃
*        ┃       ┃
*        ┗━┓   ┏━┛
*          ┃   ┃ Code is far away from bug with the animal protecting          
*          ┃   ┃ 神兽保佑,代码无bug
*          ┃   ┃           
*          ┃   ┃       
*          ┃   ┃
*          ┃   ┃           
*          ┃   ┗━━━┓
*          ┃       ┣┓
*          ┃       ┏┛
*          ┗┓┓┏━┳┓┏┛
*           ┃┫┫ ┃┫┫
*           ┗┻┛ ┗┻┛
*/

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<bitset>
#include<assert.h>
#define inc(i,l,r) for(int i=l;i<=r;i++)
#define dec(i,l,r) for(int i=l;i>=r;i--)
#define link(x) for(edge *j=h[x];j;j=j->next)
#define mem(a) memset(a,0,sizeof(a))
#define ll long long
#define eps 1e-12
#define succ(x) (1LL<<(x))
#define lowbit(x) (x&(-x))
#define sqr(x) ((x)*(x))
#define mid ((x+y)>>1)
#define NM 100005
#define nm 11
#define pi 3.1415926535897931
const ll inf=998244353;
using namespace std;
ll read(){
ll x=0,f=1;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
return f*x;
}




int n;
ll _c,_d,c[NM],d[NM],b[NM];

inline void reduce(ll&x){x+=x>>63&inf;}
inline ll qpow(ll x,ll t){
ll s=1;
for(;t;t>>=1,x=sqr(x)%inf)if(t&1)s=s*x%inf;
return s;
}

int main(){
n=read();_c=read()%(inf-1);_d=read()%(inf-1);int _=read();
_c-=_d;_d=inf-1-_d;
if(_c<0)_c=inf-1+_c;
inc(i,1,n)c[i]=qpow(i,_c),d[i]=qpow(i,_d);
inc(i,1,n)for(int j=i<<1;j<=n;j+=i)reduce(c[j]-=c[i]);
inc(i,1,n)c[i]=qpow(c[i],inf-2);
while(_--){
inc(i,1,n)b[i]=read()*d[i]%inf;
inc(i,1,n)for(int j=i<<1;j<=n;j+=i)reduce(b[j]-=b[i]);
bool _f=true;
inc(i,1,n)if(c[i]==0&&b[i]!=0){_f=false;break;}else b[i]=b[i]*c[i]%inf;
if(!_f){printf("-1\n");continue;}
dec(i,n,1)for(int j=i<<1;j<=n;j+=i)reduce(b[i]-=b[j]);
inc(i,1,n)b[i]=b[i]*d[i]%inf;
inc(i,1,n)printf("%lld%c",b[i]," \n"[i==n]);
}
return 0;
}