QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#20666 | #2574. Fancy Arrays | dsakhdkas# | WA | 7ms | 14504kb | C++ | 2.4kb | 2022-02-17 15:08:03 | 2022-05-03 10:59:01 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int Mod=1e9+7;
long long m,n;
int nu,Q,p[20],q[20],h[20],f[65][20],num,A[65][260][260],M[260][260],tmp[20],c[20][20],a[260][20],C[260][260];
bool fla;
void dfs(int k)
{
if (k>nu) {
if (!fla) {fla=true;return;}
num++;
for (int i=1;i<=nu;i++)
a[num][i]=tmp[i];
return ;
}
for (int i=0;i<=q[k];i++) {
tmp[k]=i;
dfs(k+1);
}
return;
}
void Mul(int n)
{
for (int i=1;i<=num;i++)
for (int j=1;j<=num;j++)
for (int k=1;k<=num;k++)
A[n][i][j]+=1LL*A[n-1][i][k]*A[n-1][k][j]%Mod,A[n][i][j]%=Mod;
return ;
}
void Mul_(int n)
{
for (int i=1;i<=num;i++)
for (int j=1;j<=num;j++)
C[i][j]=0;
for (int i=1;i<=num;i++)
for (int j=1;j<=num;j++)
for (int k=1;k<=num;k++)
C[i][j]+=1LL*A[n][i][k]*M[k][j]%Mod,C[i][j]%=Mod;
for (int i=1;i<=num;i++)
for (int j=1;j<=num;j++)
M[i][j]=C[i][j];
return ;
}
int main()
{
scanf("%lld%d",&m,&Q);
int t=0;
for (int i=2;i<=sqrt(m);i++)
if (m%i==0) {
t++;
while (m%i==0) p[t]++,m/=i;
}
if (m>1) p[++t]=1;
sort(p+1,p+t+1);
for (int i=1;i<=t;i++)
if (p[i]!=p[i-1]) q[++nu]=1,h[nu]=p[i];
else q[nu]++;
for (int i=1;i<=60;i++) {
f[i][0]=1;
for (int j=1;j<=t;j++)
f[i][j]=1LL*f[i][j-1]*i%Mod;
}
for (int i=0;i<=t;i++) {
c[i][0]=1;
for (int j=1;j<=i;j++)
c[i][j]=(c[i-1][j]+c[i-1][j-1])%Mod;
}
fla=false;
dfs(1);
for (int i=1;i<=num;i++)
for (int j=1;j<=num;j++) {
fla=false;A[0][j][i]=1;
for (int k=1;k<=nu;k++) {
if (a[j][k]==0) continue;
if (a[j][k]>0&&a[i][k]>0) fla=true;
if (a[j][k]>=a[i][k])
A[0][j][i]=1LL*A[0][j][i]*c[q[k]-a[i][k]][a[j][k]-a[i][k]]%Mod*f[h[k]][a[j][k]]%Mod;
else A[0][j][i]=1LL*A[0][j][i]*c[a[i][k]][a[j][k]]%Mod*f[h[k]][a[j][k]]%Mod;
}
if (!fla) A[0][j][i]=0;
}
for (int i=1;i<=60;i++)
Mul(i);
for (int i1=1;i1<=Q;i1++) {
scanf("%lld",&n);
memset(M,0,sizeof(M));
for (int i=1;i<=num;i++)
M[i][i]=1;
n--;
for (int i=0;i<=60;i++)
if ((n>>i)&1) Mul_(i);
int ans=0;
for (int i=1;i<=num;i++) {
int ss=1;
for (int j=1;j<=nu;j++)
ss=1LL*ss*c[q[j]][a[i][j]]%Mod*f[h[j]][a[i][j]]%Mod;
for (int j=1;j<=num;j++)
ans=(ans+1LL*M[j][i]*ss%Mod)%Mod;
}
if (n==0) ans++;
printf("%d\n",ans);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 14468kb
input:
12 3 1 2 3
output:
6 21 91
result:
ok 3 number(s): "6 21 91"
Test #2:
score: 0
Accepted
time: 4ms
memory: 4084kb
input:
1 150 471816347971198367 934144370769132530 85747619384378846 928941512582005725 154937870030720168 947932149793416512 27783441557851811 522085897018258944 254251197759739965 280173028039582607 323577718378116194 390211126917894813 349211961997885462 482844442408522462 582732208453073301 94800734555...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
result:
ok 150 numbers
Test #3:
score: 0
Accepted
time: 1ms
memory: 14392kb
input:
2 150 879653409269605014 957081824205994700 92943925332284309 70508831927780168 72367833784810922 57052500883916366 260855517197770739 493364569696106472 261906268272035425 712282959082227662 35005533487670014 740269757357303611 472541044721679500 231355986572948422 563516773952248704 38987628675191...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
result:
ok 150 numbers
Test #4:
score: 0
Accepted
time: 7ms
memory: 14388kb
input:
4 150 833174642454220423 721913650877167279 111257970647375842 922819627392160450 408011919008881312 938552585499192014 401181394137854787 154596954164557809 43303362814617574 450360165684736834 713407776281798115 265067947883317301 820681723927726574 17493726254665319 431343457571478167 51814600647...
output:
468840309 547289647 533838877 966360705 857529002 153274687 262629852 52838138 491303862 824933368 322126614 254980983 479226482 849822478 733697869 39083554 972201092 931290745 94464717 488665996 671570906 328618580 560220503 648667666 629662517 387210606 508021018 647625623 446432016 725472621 181...
result:
ok 150 numbers
Test #5:
score: 0
Accepted
time: 1ms
memory: 14504kb
input:
12 150 866520608211357891 826644240983841587 604468068635680936 683891212731586479 729458231854829796 199304421232371994 115565992620864149 582246847462487026 45026322404633290 991496269676336501 828552610616377158 777876324164467943 21599638116777490 828672919384884473 156000006365142361 1075758095...
output:
779414664 514445561 232707217 332166208 129233036 140771797 795601301 985364453 520952055 724746825 753012961 330741891 856478920 617535185 769187104 694821591 377746976 624170068 604988921 681705434 307373491 860391243 993177813 401466218 638396860 81657365 567590547 536248402 218207546 850043246 7...
result:
ok 150 numbers
Test #6:
score: -100
Wrong Answer
time: 2ms
memory: 14500kb
input:
60 150 942384627889050160 632722531683900587 323010899964408037 768156669746553097 910441269274010456 574994561230251602 991998693470233584 946559918384472428 688850429932902531 546016664495112655 911292584182165502 544392675853675112 286896336919591702 26067995914490533 342959982557875555 652184567...
output:
72340740 635427261 889487100 296506578 797006457 852515567 631833739 248239310 249432243 20106712 954790981 443917302 271102086 59033235 801761065 662187367 463764661 675055317 40744376 474543136 440202608 422904552 899516375 985153836 679950352 923185419 68353665 367934935 844449432 736585690 88998...
result:
wrong answer 1st numbers differ - expected: '932200580', found: '72340740'