Luogu P4902 乘积

题目
我们要求的是

\[\prod\limits_{i=a}^b\prod\limits_{j=1}^i(\frac ij)^{\lfloor\frac ij\rfloor} \]

先把它拆开

\[\prod\limits_{i=a}^b\prod\limits_{j=1}^ii^{\lfloor\frac ij\rfloor}(\frac1{\prod\limits_{i=a}^b\prod\limits_{j=1}^ij^{\lfloor\frac ij\rfloor}}) \]

对于右边,我们把\(j\in[1,i]\)换成\(j\in[1,b]\)是没有任何问题的。因为\(\forall j\in(i,b],\lfloor\frac ij\rfloor=0\),相当于多乘了几个\(1\)
然后再交换右边的连乘符号

\[\prod\limits_{i=a}^b\prod\limits_{j=1}^ii^{\lfloor\frac ij\rfloor}(\frac1{\prod\limits_{j=1}^b\prod\limits_{i=a}^bj^{\lfloor\frac ij\rfloor}}) \]

我们把连乘换成指数的求和

\[\prod\limits_{i=a}^bi^{\sum\limits_{j=1}^i\lfloor\frac ij\rfloor}(\frac1{\prod\limits_{j=1}^bj^{\sum\limits_{i=a}^b\lfloor\frac ij\rfloor}}) \]

然后容斥一下

\[\prod\limits_{i=1}^bi^{\sum\limits_{j=1}^i\lfloor\frac ij\rfloor}\prod\limits_{j=1}^{a-1}j^{\sum\limits_{i=1}^{a-1}\lfloor\frac ij\rfloor}(\frac1{\prod\limits_{j=1}^bj^{\sum\limits_{i=1}^b\lfloor\frac ij\rfloor}\prod\limits_{i=1}^{a-1}i^{\sum\limits_{j=1}^i\lfloor\frac ij\rfloor}}) \]

\[let\ a=a-1,f(n)=\prod\limits_{i=1}^ni^{\sum\limits_{j=1}^i\lfloor\frac ij\rfloor},g(n)=\prod\limits_{j=1}^nj^{\sum\limits_{i=1}^n\lfloor\frac ij\rfloor} \]

则要求的式子就变成了

\[f(b)g(a)(\frac1{f(a)g(b)}) \]

所以如果我们能够以\(O(nlog\ n)\)的复杂的筛出\(f,g\)的话就能解决问题。
首先计算\(f\)

\[let\ \sigma(n)=\sum\limits_{d|n}1,d(n)=\sum\limits_{i=1}^n\sigma(i) \]

考虑到枚举约数和枚举倍数的等价性

\[d(n)=\sum\limits_{i=1}^n\lfloor\frac ni\rfloor \]

\[f(n)=\prod\limits_{i=1}^ni^{d(i)} \]

显然其递推式为

\[f(n)=f(n-1)n^{d(n)} \]

所以我们可以\(O(nlog\ n)\)筛出\(\sigma\)即除数函数,然后前缀和求出,\(d\),再按递推式求出\(f\)
注意\(d\)是作为指数存在,所以取模时需要对\(P-1\)取模。
再计算\(g\)

\[let\ t(n)=\frac{g(n)}{g(n-1)}=\prod\limits_{i=1}^ni^{\lfloor\frac ni\rfloor},h(n)=\frac{t(n)}{t(n-1)}=\prod\limits_{d|n}d \]

显然我们可以\(O(nlog\ n)\)筛出\(h\)即约数积函数,然后做两遍前缀积就可以得到\(g\)

#include<bits/stdc++.h>
using namespace std;
namespace IO
{
    char ibuf[(1<<21)+1],obuf[(1<<21)+1],st[15],*iS,*iT,*oS=obuf,*oT=obuf+(1<<21);
    char Get(){return (iS==iT? (iT=(iS=ibuf)+fread(ibuf,1,(1<<21)+1,stdin),(iS==iT? EOF:*iS++)):*iS++);}
    void Flush(){fwrite(obuf,1,oS-obuf,stdout),oS=obuf;}
    void Put(char x){*oS++=x;if(oS==oT)Flush();}
    int read(){int x=0;char ch=Get();while(ch>57||ch<48)ch=Get();while(ch>=48&&ch<=57)x=x*10+(ch^48),ch=Get();return x;}
    void write(int x){int top=0;if(!x)Put('0');while(x)st[++top]=(x%10)+48,x/=10;while(top)Put(st[top--]);Put('\n');}
}
using namespace IO;
const int N=1000007,A=1000000,P=993244853;
int inc(int a,int b,int p=P){a+=b;return a>=p? a-p:a;}
int mul(int a,int b){return 1ll*a*b%P;}
int power(int a,int k){int r=1;for(;k;k>>=1,a=mul(a,a))if(k&1)r=mul(a,r);return r;}
int d[N],s[N],f[N];
int main()
{
    int i,j,n,a,b;
    s[0]=f[0]=1;
    for(i=1;i<=A;++i) s[i]=1;
    for(i=1;i<=A;++i) for(j=i;j<=A;j+=i) ++d[j],s[j]=mul(s[j],i);
    for(i=1;i<=A;++i) d[i]=inc(d[i],d[i-1],P-1),f[i]=mul(f[i-1],power(i,d[i])),s[i]=mul(s[i],s[i-1]);
    for(i=1;i<=A;++i) s[i]=mul(s[i],s[i-1]);
    for(n=read();n;--n) a=read()-1,b=read(),write(mul(mul(mul(power(f[a],P-2),f[b]),power(s[b],P-2)),s[a]));
    return Flush(),0;
}
posted @ 2019-11-22 20:51  Shiina_Mashiro  阅读(85)  评论(0编辑  收藏  举报