QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#301455#2574. Fancy ArrayszhouhuanyiTL 5ms7948kbC++142.3kb2024-01-09 22:13:492024-01-09 22:13:50

Judging History

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

  • [2024-01-09 22:13:50]
  • 评测
  • 测评结果:TL
  • 用时:5ms
  • 内存:7948kb
  • [2024-01-09 22:13:49]
  • 提交

answer

#include<iostream>
#include<cstdio>
#define N 128
#define M 53
#define W 59
#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[W+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<=W;++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<=W;++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: 3ms
memory: 7708kb

input:

12 3
1
2
3

output:

6
21
91

result:

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

Test #2:

score: 0
Accepted
time: 3ms
memory: 7692kb

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: 4ms
memory: 7752kb

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: 0ms
memory: 7708kb

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: 0ms
memory: 7948kb

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: 0
Accepted
time: 4ms
memory: 7752kb

input:

60 150
942384627889050160
632722531683900587
323010899964408037
768156669746553097
910441269274010456
574994561230251602
991998693470233584
946559918384472428
688850429932902531
546016664495112655
911292584182165502
544392675853675112
286896336919591702
26067995914490533
342959982557875555
652184567...

output:

932200580
903893996
357154050
968506185
742674333
892926972
955069213
359920050
662550206
709081432
789644301
156063250
217976189
960971758
150053868
654190187
4302337
143734760
134807911
682516411
414799732
641288662
760159256
358958740
258320312
382386241
181861029
980283133
85490921
826348474
915...

result:

ok 150 numbers

Test #7:

score: 0
Accepted
time: 4ms
memory: 7776kb

input:

420 150
652643102578585626
815592668110344564
80182963922677648
329298533050661052
888030230126602620
366600500217079827
410187526382051676
102382793137115355
274746471179172353
296927801740189908
315100659826195468
117705908453673624
768586284103816365
68311227918233771
180984322159013983
934861174...

output:

134106992
679303625
834034299
991574091
800679260
187365176
338079081
632426140
889580947
359580371
291928987
167306560
879609773
6190610
230006744
690370376
32999033
279019618
258258432
470436938
155317311
403241661
56033583
77078814
968951238
37546219
154714275
643164852
354497133
450000862
491335...

result:

ok 150 numbers

Test #8:

score: 0
Accepted
time: 4ms
memory: 7824kb

input:

4620 150
297322315854726773
280471159266106599
699801246349452330
65496083279950550
871398581662271626
856073774431287314
261685312184467620
794118362921655401
559675718578383421
852245166791982043
206354949512966676
74912770463068510
763582430583263339
682350125491835657
902249948237866072
34545707...

output:

986044811
103091966
935113777
583542759
22612061
321972881
54295640
624452113
567960641
103460045
69195739
318209967
920265424
943514529
699397996
726777723
966124283
112846048
521332082
451189762
618299099
289852269
781213823
983239700
562263268
288749357
822981064
614412918
688340550
849355405
193...

result:

ok 150 numbers

Test #9:

score: 0
Accepted
time: 0ms
memory: 7824kb

input:

60060 150
321042833671319069
814779641977482535
206907881258140242
767656477507514350
965658116010881153
888046414032773423
752829149707163137
37075116613065442
825910891680936350
565535799506538902
42554938199054555
8281169553665359
762279657524288035
721144630802920750
317996750034298205
925077279...

output:

74005897
258648189
740728514
951722800
984957343
681780261
798706732
228390199
206326177
200055927
952166057
303251351
111205729
988934736
386979870
98349805
70618759
601550202
318699486
271487431
26515923
34666519
949278619
788840050
6330372
598336830
924291965
505223310
870746431
867707461
8648310...

result:

ok 150 numbers

Test #10:

score: 0
Accepted
time: 0ms
memory: 7832kb

input:

1021020 150
150546375236259464
956402079575897507
968744791372351937
13463566892651571
692798889396376374
916586573012377121
924472563871303333
240428216767012645
201769115986535644
434378618828710810
128004453899931139
206891611964666356
645377478508905195
815021290558325956
719028170873713564
1930...

output:

262996144
987798410
14820748
289072324
963824210
979941239
585955578
518300473
129823444
534729569
25449906
226686496
186371714
410946085
594251433
271314073
738280663
196494119
903815636
879387765
824397505
708849774
389012220
686309715
258859407
35876421
991782680
75766926
93598945
35416944
774534...

result:

ok 150 numbers

Test #11:

score: 0
Accepted
time: 5ms
memory: 7924kb

input:

19399380 150
236744048803792416
885780066050607118
828951197292810646
284651790382979731
606532017420458180
560079481459864793
539163183635352360
482802457708205662
228992116223889573
913777324385054202
906030569026659864
377107783185934542
483336437389083834
321631993535981481
724639864832760572
90...

output:

12331829
642558635
824299074
413423313
999070667
197490327
97388134
22927131
388819376
114986062
187368983
954105673
443408571
53711161
796465194
241085176
578817122
130283588
553303116
777107049
199876531
26416438
518944833
431524394
261407022
744927174
929895387
750357617
538155073
131439019
71960...

result:

ok 150 numbers

Test #12:

score: -100
Time Limit Exceeded

input:

69657034752000 150
403776100446711204
876994814256699519
358809067106070890
412670168821855830
205995758175869757
572442827386738585
923826004198949890
339609305869204070
520518044744048844
294563501488160749
400224049857958833
591478758481285289
494376786934891788
656940592622961750
649287802846795...

output:


result: