QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#276763#2856. 数字表格SoyTony100 ✓604ms23700kbC++141.9kb2023-12-06 10:21:332023-12-06 10:21:34

Judging History

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

  • [2023-12-06 10:21:34]
  • 评测
  • 测评结果:100
  • 用时:604ms
  • 内存:23700kb
  • [2023-12-06 10:21:33]
  • 提交

answer

#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
typedef double db;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const int maxn=1e6+10;
const int maxm=1e6+10;
const int mod=1e9+7;
const ll base=1e8;
const ull base1=10007;
const ull base2=19260817;
const int maxxn=0x3f3f3f3f;
const int minxn=-0x3f3f3f3f;
const db inf=1e13;
const db eps=1e-9;
inline ll read(){
    ll x=0,w=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')w=-1;c=getchar();}
    while(c<='9'&&c>='0'){x=(x<<3)+(x<<1)+c-'0';c=getchar();}
    return x*w;
}
int t,n,m;
int pr[maxn],vis[maxn],mu[maxn],f[maxn],inv[maxn],g[maxn];
inline int q_pow(int x,int p){
	int ans=1;
	while(p){
		if(p&1) ans=1ll*ans*x%mod;
		x=1ll*x*x%mod;
		p>>=1;
	}
	return ans;
}
inline void pre(){
	mu[1]=1,f[1]=inv[1]=g[0]=g[1]=1;
	for(int i=2;i<=1e6;++i){
		f[i]=(f[i-2]+f[i-1])%mod;
		inv[i]=q_pow(f[i],mod-2);
		g[i]=1;
		if(!vis[i]) pr[++pr[0]]=i,mu[i]=-1;
		for(int j=1;j<=pr[0]&&i*pr[j]<=1e6;++j){
			vis[i*pr[j]]=1;
			if(i%pr[j]==0){
				mu[i*pr[j]]=0;
				break;
			}
			mu[i*pr[j]]=-mu[i];
		}
	}
	for(int i=1;i<=1e6;++i){
		if(!mu[i]) continue;
		for(int j=i;j<=1e6;j+=i){
			if(mu[i]==1) g[j]=1ll*g[j]*f[j/i]%mod;
			else g[j]=1ll*g[j]*inv[j/i]%mod;
		}
	}
	for(int i=2;i<=1e6;++i) g[i]=1ll*g[i-1]*g[i]%mod;
	/*for(int i=1;i<=100;++i){
		printf("%d %d %d %d %d\n",pr[i],mu[i],f[i],inv[i],g[i]);
	}*/
}
int main(){
	pre();
	t=read();
	while(t--){
		n=read(),m=read();
		if(n>m) swap(n,m);
		int ans=1;
		for(int l=1,r;l<=n;l=r+1){
			r=min(n/(n/l),m/(m/l));
			int tmp=1ll*g[r]*q_pow(g[l-1],mod-2)%mod;
			ans=1ll*ans*q_pow(tmp,1ll*(n/l)*(m/l)%(mod-1))%mod;
		}
		printf("%d\n",ans);
	}
	return 0;
}

詳細信息

Test #1:

score: 10
Accepted
time: 178ms
memory: 23464kb

input:

1000
82 5
85 13
18 82
39 47
85 97
28 33
72 40
38 43
76 44
9 45
57 96
3 54
60 20
43 30
45 46
11 53
14 84
50 90
10 39
39 20
70 50
95 13
36 54
47 82
47 52
68 44
36 53
13 94
100 69
56 80
16 28
93 10
52 39
66 75
68 17
37 74
66 64
5 69
34 84
74 21
44 67
36 3
26 55
20 54
43 50
67 14
49 54
13 11
4 59
83 72
...

output:

697857603
513287135
493843565
685803126
740209982
40610353
396156831
744451085
76570868
570036963
171027959
262144
893084879
939049770
926146193
722919138
964641357
942426458
622528402
451760491
14237564
225318722
518777888
449825043
341812093
432079000
772254207
169012750
411792446
748968062
756385...

result:

ok 1000 lines

Test #2:

score: 10
Accepted
time: 185ms
memory: 23344kb

input:

1000
456 760
791 350
655 528
2 279
69 639
512 306
308 162
717 572
992 483
222 419
425 368
391 134
541 346
150 960
852 350
270 993
338 455
197 621
281 194
446 443
157 488
776 127
54 512
902 953
321 874
397 451
655 813
305 303
372 210
655 671
689 895
332 867
219 734
189 279
490 563
45 794
43 1
907 328...

output:

384572586
128416505
177153016
1
792110166
378466851
634682075
140555279
785606784
224545347
480461357
787221913
152690988
276697635
873944871
15937156
787784125
74845458
378183569
770058883
553415281
664773218
54099655
4520332
136745043
642040144
647801092
694272606
411423640
772548747
991414475
262...

result:

ok 1000 lines

Test #3:

score: 10
Accepted
time: 189ms
memory: 23404kb

input:

1000
834 24
939 905
741 833
728 412
665 30
90 620
517 891
130 313
639 707
544 959
223 611
85 709
250 300
322 983
393 173
407 404
831 110
165 881
991 422
885 165
819 590
815 411
926 844
220 395
363 553
555 993
435 636
704 644
900 365
424 960
149 578
894 636
986 805
554 661
798 699
77 762
172 751
166 ...

output:

644802145
232279121
379400155
444492502
954058278
813885568
18387337
502115986
340496387
84878668
494148625
561893309
729783825
495024707
306032686
744614950
310694222
151470960
67195602
891797129
572646117
912571586
762567644
631897452
923582319
898125642
924489975
992290630
669842153
864854675
343...

result:

ok 1000 lines

Test #4:

score: 10
Accepted
time: 173ms
memory: 23700kb

input:

3
454940 562672
112643 767306
907862 417181

output:

695663156
628427697
686722724

result:

ok 3 lines

Test #5:

score: 10
Accepted
time: 170ms
memory: 23644kb

input:

3
745197 513056
269960 979569
208740 376976

output:

634928413
640591579
861814959

result:

ok 3 lines

Test #6:

score: 10
Accepted
time: 197ms
memory: 23420kb

input:

3
121356 462155
298930 200313
460606 503275

output:

748574275
576920
859930990

result:

ok 3 lines

Test #7:

score: 10
Accepted
time: 589ms
memory: 23412kb

input:

1000
283558 168544
143615 807608
461779 307243
759795 341819
791247 562279
899971 582242
112436 804931
512924 539518
506466 351699
256430 581061
65275 126030
432494 604369
369382 716240
614292 212703
246925 304537
770781 488081
760542 135820
242826 868717
832206 664944
689055 660507
477009 178162
25...

output:

283014868
990243232
388248159
616196065
219886182
309382041
448679213
534956539
918843207
55781398
824669761
474166751
307997809
151932376
500358371
591586078
682389632
341823993
554507625
688852617
634347229
172864935
122553460
202758604
858950400
301189134
1594673
617393878
170625580
610595922
172...

result:

ok 1000 lines

Test #8:

score: 10
Accepted
time: 588ms
memory: 23472kb

input:

1000
440274 901599
691601 797856
838055 495802
684464 663111
25477 958082
634124 986486
784532 84086
595489 737743
803588 746107
507375 445527
429256 581591
105532 192505
129686 524151
510160 547137
9897 903082
906231 195234
529919 163684
992899 24432
718107 697468
300039 232039
619908 616814
437725...

output:

365320913
681614706
847286353
671477779
264121697
585088898
368905317
11027303
889121172
109652792
80510572
642059979
480108117
599586524
900360019
164051816
395310915
906701911
787811872
790784785
818963886
763793845
335411670
167129596
14877864
617021327
830035095
90699668
633416819
100892835
2193...

result:

ok 1000 lines

Test #9:

score: 10
Accepted
time: 604ms
memory: 23472kb

input:

1000
82099 145723
916973 256099
847467 5679
827410 634711
814947 648717
452883 705336
279959 643364
526334 114296
171651 647528
93859 297708
405036 664496
286039 691597
194839 977656
79922 965177
949648 362655
190289 994355
414692 338602
373526 895198
362151 16511
279011 797510
181551 695915
901667 ...

output:

892557352
602766132
609986864
451863890
987591917
727546364
493768397
360043516
725932491
358432557
924555808
537966114
376147353
644329506
82216168
421049387
709247573
201697130
818623765
165832955
251779127
289533274
127590777
387082723
933248973
862380388
298729759
964486678
532229940
144255370
9...

result:

ok 1000 lines

Test #10:

score: 10
Accepted
time: 590ms
memory: 23472kb

input:

1000
289425 176253
54044 388424
551782 18069
271647 334132
2932 750739
280736 422385
118021 716182
675003 529602
507815 849891
921488 524106
871151 656480
728325 392405
388722 388186
661186 781712
111306 853376
921908 442700
128791 264037
219787 338943
816123 586242
51579 729859
671516 827378
823742...

output:

941313418
330479975
400191059
317961212
608283349
768465305
270252947
548702642
348199404
783788857
325184947
319667541
309227985
601658259
556002932
783792811
164680409
830772331
781714629
345353453
68627791
609976729
790036886
838208236
772779707
712165773
786518563
5069623
916902879
262508186
809...

result:

ok 1000 lines