QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#20508 | #2574. Fancy Arrays | Appleblue17# | WA | 69ms | 36072kb | C++17 | 2.9kb | 2022-02-16 12:43:24 | 2022-05-03 10:19:26 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=1e8+5,M=220,mod=1e9+7,B=8;
long long m,n;
int q,s=1,ans[M];
bool pd[N];
int prime[N];
int cnt;
int mul[M],inv[M];
int C(int m,int n){
if(m<0 || n<0 || m<n) return 0;
return 1ll*mul[m]*inv[n]%mod*inv[m-n]%mod;
}
int ksm(int f,int x){
int tot=1;
while(x){
if(x & 1ll) tot=1ll*tot*f%mod;
f=1ll*f*f%mod;
x>>=1ll;
}
return tot;
}
void init(int lim){
mul[0]=inv[0]=1;
for(int i=1;i<=lim;i++) mul[i]=1ll*mul[i-1]*i%mod;
inv[lim]=ksm(mul[lim],mod-2);
for(int i=lim-1;i>=1;i--) inv[i]=1ll*inv[i+1]*(i+1)%mod;
pd[1]=1;
for(int i=2;i<=lim;i++){
if(!pd[i]) prime[++cnt]=i;
for(int j=1;j<=cnt && i*prime[j]<=lim;j++){
pd[i*prime[j]]=1;
if(i%prime[j]==0) break;
}
}
}
int tmp[M],num[M],e[M],id;
struct mtr{
int t[M][M];
}P,A,R[M][B];
mtr getnew(){
mtr tmp;
for(int i=1;i<=s;i++)
for(int j=1;j<=s;j++)
tmp.t[i][j]=0;
for(int j=1;j<=s;j++) tmp.t[j][j]=1;
return tmp;
}
mtr operator *(mtr a,mtr b){
mtr tot;
for(int i=1;i<=s;i++)
for(int j=1;j<=s;j++)
tot.t[i][j]=0;
for(int i=1;i<=s;i++)
for(int k=1;k<=s;k++)
for(int j=1;j<=s;j++)
tot.t[i][j]=(tot.t[i][j]+1ll*a.t[i][k]*b.t[k][j]%mod)%mod;
return tot;
}
mtr ksm(mtr a,long long x){
mtr tot=getnew();
while(x){
if(x & 1ll) tot=a*tot;
a=a*a;
x>>=1ll;
}
return tot;
}
int a[M],b[M],val[M];
int main(){
init(M-5);
cin>>m>>q;
long long x=m;
for(int i=1;i<=cnt && prime[i]<=x;i++){
if(x%prime[i]) continue;
int tot=0;
while(x%prime[i]==0) tot++,x/=prime[i];
tmp[tot]++;
}
if(x>1) tmp[1]++;
for(int i=1;i<=80;i++)
if(tmp[i]){
num[++id]=tmp[i];
e[id]=i;
s*=num[id]+1;
}
for(int i=1;i<=s;i++){
for(int j=1;j<=s;j++){
int x=i-1;
for(int t=1;t<=id;t++) a[t]=x%(num[t]+1),x/=(num[t]+1);
int y=j-1;
for(int t=1;t<=id;t++) b[t]=y%(num[t]+1),y/=(num[t]+1);
int sum=1,tot=1;
for(int t=1;t<=id;t++) sum=1ll*sum*C(num[t],b[t])%mod*ksm(e[t],b[t])%mod;
for(int t=1;t<=id;t++){
if(a[t]+b[t]>num[t]){
tot=0;
break;
}
tot=1ll*tot*C(num[t]-a[t],b[t])%mod*ksm(e[t],b[t])%mod;
}
P.t[i][j]=(sum+mod-tot)%mod;
}
}
for(int i=1;i<=s;i++){
int x=i-1;
for(int t=1;t<=id;t++) a[t]=x%(num[t]+1),x/=(num[t]+1);
int tot=1;
for(int t=1;t<=id;t++)
tot=1ll*tot*C(num[t],a[t])%mod*ksm(e[t],a[t])%mod;
val[i]=tot;
}
for(int i=1;i<=s;i++) A.t[i][1]=1;
R[0][1]=P;
for(int i=0;i<=16;i++){
if(i) R[i][1]=R[i-1][B-1]*R[i-1][1];
for(int t=2;t<B;t++) R[i][t]=R[i][t-1]*R[i][1];
}
for(int i=1;i<=q;i++){
cin>>n; n--;
// n=314719601137586866;
mtr T=getnew();
for(int t=0;t<=16;t++){
long long x=n/(long long)(pow(B,t))%B;
if(x) T=T*R[t][x];
}
T=T*A;
int tot=0;
for(int i=1;i<=s;i++) tot=(tot+1ll*T.t[i][1]*val[i]%mod)%mod;
cout<<tot<<endl;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 5ms
memory: 36072kb
input:
12 3 1 2 3
output:
6 21 91
result:
ok 3 number(s): "6 21 91"
Test #2:
score: 0
Accepted
time: 69ms
memory: 34704kb
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: 60ms
memory: 35340kb
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: -100
Wrong Answer
time: 56ms
memory: 35268kb
input:
4 150 833174642454220423 721913650877167279 111257970647375842 922819627392160450 408011919008881312 938552585499192014 401181394137854787 154596954164557809 43303362814617574 450360165684736834 713407776281798115 265067947883317301 820681723927726574 17493726254665319 431343457571478167 51814600647...
output:
230167296 196628211 574776726 834884783 805729432 156220538 919383035 302630925 606962124 322273303 372184850 248449793 154104231 12142823 164776225 238718919 692409435 45431754 608508235 912435634 259971542 348610214 326804800 314597985 219912962 816117215 502518548 201695447 626784843 54550620 877...
result:
wrong answer 1st numbers differ - expected: '468840309', found: '230167296'