QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#301454#2574. Fancy ArrayszhouhuanyiWA 3ms7428kbC++142.3kb2024-01-09 22:09:252024-01-09 22:09:27

Judging History

你现在查看的是最新测评结果

  • [2024-01-09 22:09:27]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:7428kb
  • [2024-01-09 22:09:25]
  • 提交

answer

#include<iostream>
#include<cstdio>
#define N 128
#define M 53
#define mod 1000000007
using namespace std;
long long read()
{
	char c=0;
	long long sum=0;
	while (c<'0'||c>'9') c=getchar();
	while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
	return sum;
}
void Adder(int &x,int d)
{
	x+=d;
	if (x>=mod) x-=mod;
	return;
}
void Adder2(int &x,int d)
{
	x+=d;
	if (x<0) x+=mod;
	return;
}
int MD(int x)
{
	return x>=mod?x-mod:x;
}
int MD2(int x)
{
	return x<0?x+mod:x;
}
long long m,n;
int q,ans,res=1,C[M+1][M+1],pws[M+1][M+1],scnt[N+1],delta[N+1],delta2[N+1],dp[N+1],DP[N+1],F[N+1];
struct matrix
{
	int d[N+1][N+1];
};
matrix zero,c,nw,e,pw[M+1];
matrix operator * (matrix a,matrix b)
{
	c=zero;
	for (int k=1;k<=res;++k)
		for (int i=1;i<=res;++i)
			for (int j=1;j<=res;++j)
				Adder(c.d[i][j],1ll*a.d[i][k]*b.d[k][j]%mod);
	return c;
}
int main()
{
	int cnt,d,rst,rst2;
	long long x;
	for (int i=0;i<=M;++i) C[i][0]=1;
	for (int i=1;i<=M;++i)
		for (int j=1;j<=i;++j)
			C[i][j]=MD(C[i-1][j-1]+C[i-1][j]);
	x=m=read(),q=read();
	for (int i=2;i*i<=m;++i)
		if (x%i==0)
		{
			cnt=0;
			while (x%i==0) x/=i,cnt++;
			scnt[cnt]++;
		}
	if (x!=1) scnt[1]++;
	for (int i=1;i<=M;++i) res*=(scnt[i]+1);
	for (int i=1;i<=res;++i) e.d[i][i]=1;
	for (int i=0;i<=M;++i)
	{
		pws[i][0]=1;
		for (int j=1;j<=M;++j) pws[i][j]=1ll*pws[i][j-1]*i%mod;
	}
	for (int i=1;i<=res;++i)
		for (int j=1;j<=res;++j)
		{
			d=i-1;
			for (int k=1;k<=M;++k) delta[k]=d%(scnt[k]+1),d/=(scnt[k]+1);
			d=j-1;
			for (int k=1;k<=M;++k) delta2[k]=d%(scnt[k]+1),d/=(scnt[k]+1);
			rst=rst2=1;
			for (int k=1;k<=M;++k) rst=1ll*rst*C[scnt[k]][delta2[k]]%mod*pws[k][delta2[k]]%mod,rst2=1ll*rst2*C[scnt[k]-delta[k]][delta2[k]]%mod*pws[k][delta2[k]]%mod;
			if (i==1) DP[j]=rst;
			Adder2(rst,-rst2),nw.d[i][j]=rst;
		}
	pw[0]=nw;
	for (int i=1;i<=M;++i) pw[i]=pw[i-1]*pw[i-1];
	while (q--)
	{
		n=read(),ans=0;
		for (int i=1;i<=res;++i) dp[i]=DP[i];
		for (int i=0;i<=M;++i)
			if (((n-1)>>i)&1)
			{
				for (int k=1;k<=res;++k) F[k]=0;
				for (int k=1;k<=res;++k)
					for (int t=1;t<=res;++t)
						Adder(F[t],1ll*dp[k]*pw[i].d[k][t]%mod);
				for (int k=1;k<=res;++k) dp[k]=F[k];
			}
		for (int i=1;i<=res;++i) Adder(ans,dp[i]);
		printf("%d\n",ans);
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 7380kb

input:

12 3
1
2
3

output:

6
21
91

result:

ok 3 number(s): "6 21 91"

Test #2:

score: 0
Accepted
time: 2ms
memory: 7428kb

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: 7380kb

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: 3ms
memory: 7364kb

input:

4 150
833174642454220423
721913650877167279
111257970647375842
922819627392160450
408011919008881312
938552585499192014
401181394137854787
154596954164557809
43303362814617574
450360165684736834
713407776281798115
265067947883317301
820681723927726574
17493726254665319
431343457571478167
51814600647...

output:

271313499
196628211
601548774
560666669
236244474
156220538
121927885
304944635
358088023
322273303
679137216
190897340
114738120
849822478
747309413
687360072
258339576
25865085
624726440
137935414
690343377
193180585
115645106
514034275
509980088
989746705
208113271
451273432
501048447
883999035
8...

result:

wrong answer 1st numbers differ - expected: '468840309', found: '271313499'