QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#561075 | #6328. Many Products | pigstd | TL | 2590ms | 19540kb | C++20 | 3.6kb | 2024-09-12 19:57:58 | 2024-09-12 19:58:00 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define x first
#define y second
#define vi vector<int>
#define vpi vector<pii>
#define all(x) (x).begin(),(x).end()
using namespace std;
inline int read()
{
char c=getchar();int x=0;bool f=0;
for(;!isdigit(c);c=getchar())f^=!(c^45);
for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
if(f)x=-x;return x;
}
const int Mod=998244353;
const int M=2e5+10;
int n,a[M],m,fac[M],ifac[M];
int poww(int a,int b)
{
int res=1;
while(b)
{
if (b&1)res=res*a%Mod;
a=a*a%Mod,b>>=1;
}return res;
}
namespace poly
{
vi omega[25];
void ntt_init(int n)
{
for (int k=2,d=0;k<=n;k*=2,d++)
{
omega[d].resize(k+1);
int wn=poww(3,(Mod-1)/k),tmp=1;
for (int i=0;i<=k;i++)
omega[d][i]=tmp,tmp=tmp*wn%Mod;
}
}
void ntt(vi &c,int n,int tp)
{
vector<ull>a(n);
for (int i=0;i<n;i++)a[i]=c[i];
for (int i=1,j=0;i<n-1;i++)
{
int k=n;
do j^=(k>>=1);while(j<k);
if (i<j)swap(a[i],a[j]);
}
for (int k=1,d=0;k<n;k*=2,d++)
{
if (d==16)for (int i=0;i<n;i++)a[i]%=Mod;
for (int i=0;i<n;i+=k*2)
for (int j=0;j<k;j++)
{
int w=omega[d][tp>0?j:k*2-j];
ull u=a[i+j],v=w*a[i+j+k]%Mod;
a[i+j]=u+v;
a[i+j+k]=u-v+Mod;
}
}
if (tp>0){for (int i=0;i<n;i++)c[i]=a[i]%Mod;}
else
{
int inv=poww(n,Mod-2);
for (int i=0;i<n;i++)c[i]=a[i]%Mod*inv%Mod;
}
}
vi operator * (vi a,vi b)
{
if (a.size()==0)return a;
if (b.size()==0)return b;
int len=a.size()+b.size()-1;
int n=1;
while(n<len)n*=2;
ntt_init(n);
a.resize(n),b.resize(n);
vi c(n);
ntt(a,n,1),ntt(b,n,1);
for (int i=0;i<n;i++)c[i]=a[i]*b[i]%Mod;
ntt(c,n,-1);
c.resize(len);
return c;
}
}
using namespace poly;
vi solve(int l,int r)
{
if (l==r)return {1,a[l]};
int Mid=(l+r)>>1;
return solve(l,Mid)*solve(Mid+1,r);
}
vi get(int x)
{
vi res;
for (int i=1;i*i<=x;i++)
if (x%i==0)
{
res.pb(i);
if (i*i!=x)res.pb(x/i);
}
sort(all(res));
return res;
}
vi e[M];
int dp[10000][100];
int C(int m,int n)
{
if (n<0||m<n)return 0;
return fac[m]*ifac[n]%Mod*ifac[m-n]%Mod;
}
signed main()
{
n=read(),m=read();
for (int i=1;i<=n;i++)a[i]=read();
auto tmp=solve(1,n);
fac[0]=1;
for (int i=1;i<=n;i++)fac[i]=fac[i-1]*i%Mod;
ifac[n]=poww(fac[n],Mod-2);
for (int i=n;i>=1;i--)ifac[i-1]=ifac[i]*i%Mod;
vi x=get(m);int L=x.size();
for (int i=0;i<L;i++)
for (int j=i+1;j<L;j++)
if (x[j]%x[i]==0)e[j].pb(i);
dp[0][0]=1;
for (int i=1;i<=40;i++)
for (int j=0;j<L;j++)
for (auto k:e[j])dp[j][i]=(dp[j][i]+dp[k][i-1])%Mod;
int ans=0;
for (int i=0;i<=40;i++)
for (int j=0;j<=40;j++)
{
int val=0;
for (int a=0;a<=n;a++)
val=(val+tmp[n-a]*C(a,i)%Mod*C(n-a,j))%Mod;
for (int k=0;k<L;k++)
ans=(ans+x[k]%Mod*dp[k][i]%Mod*dp[L-k-1][j]%Mod*val)%Mod;
}
cout<<ans<<'\n';
return 0;
}
/*
1 742073813481
0
*/
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5652kb
input:
2 3 0 1
output:
10
result:
ok 1 number(s): "10"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5532kb
input:
5 1 0 1 2 3 4
output:
120
result:
ok 1 number(s): "120"
Test #3:
score: 0
Accepted
time: 3ms
memory: 7848kb
input:
10 314159265358 0 1 2 3 4 5 6 7 8 9
output:
658270849
result:
ok 1 number(s): "658270849"
Test #4:
score: 0
Accepted
time: 2549ms
memory: 18360kb
input:
200000 999999999989 823489320 406308599 710963770 183707427 192930969 941365774 318564299 391028855 945374838 651744270 515755727 220857626 599403217 214957584 335628890 771694833 40989299 34892948 630275822 869708185 432704750 924850167 707864789 232688853 406616372 529994171 782650336 979286144 65...
output:
777405593
result:
ok 1 number(s): "777405593"
Test #5:
score: 0
Accepted
time: 2557ms
memory: 18264kb
input:
199999 999999999331 969252353 737776924 108584656 914893031 394348303 484491127 481944452 120707790 396027156 912223841 673218447 285837840 782450963 144940963 892852383 782342131 655814479 1324532 794011279 219428289 470995270 489684781 347978895 102371386 546635675 585575402 940741300 644383693 67...
output:
573300948
result:
ok 1 number(s): "573300948"
Test #6:
score: 0
Accepted
time: 2590ms
memory: 19540kb
input:
200000 742073813481 681694404 632869785 595996398 549654767 229574822 571126931 469341419 702184356 904366313 746328903 842820475 578092052 586236587 796973195 766841610 123554290 666934376 118830348 326368534 40766155 790927880 880528134 890721558 357539968 885997091 937508042 5345140 189162897 200...
output:
998002127
result:
ok 1 number(s): "998002127"
Test #7:
score: -100
Time Limit Exceeded
input:
199999 963761198400 124206358 425059813 396286827 293468808 45861386 890748681 587148852 2565459 137729579 865441288 710978415 682768035 62610967 490442955 426217252 132942846 314800009 680954919 208583546 438814504 79283475 26876485 718279429 714019319 799517726 874565672 262935553 180792133 654326...
output:
150795568