UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#207718#3767. 倍数和yhmm1007281ms1152kbC++111.0kb2024-07-30 18:02:092024-07-30 20:02:20

answer

#include<bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
long long n,m,ans,T,f,a[21],k;
long long FastReadLongLong()
{
	long long x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9')
	{
		if(c=='-')
		{
			f=-1;
		}
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		x=(x<<1)+(x<<3)+(c^48),c=getchar();
	}
	return x*f;
}
long long QuickPow(long long a,long long b)
{
	long long res=1;
	while(b)
	{
		if(b&1)
		{
			res=res*a;
		}
		a=a*a;
		b>>=1;
	}
	return res;
}
void dfs(long long s,long long pos,long long x)
{
	if(!s)
	{
		k+=(m/x);
		return;
	}
	for(int i=pos;i<=n;i++)
	{
		if(!x)
		{
			dfs(s-1,i+1,a[i]);
		}
		else
		{
			dfs(s-1,i+1,a[i]/__gcd(x,a[i])*x);
		}
	}
}
int main(){
	T=FastReadLongLong();
	for(int z=1;z<=T;z++)
	{
		n=FastReadLongLong(),m=FastReadLongLong();
		for(int i=1;i<=n;i++)
		{
			a[i]=FastReadLongLong();
		}
		ans=0;
		for(int i=0;i<n;i++)
		{
			k=0;
			dfs(i+1,1,0);
			ans+=QuickPow(-1,i)*k;
		}
		printf("%lld\n",m-ans);
	}	
	return 0;
}

Details

小提示:点击横条可展开更详细的信息

Test #1:

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

input:

10
2 560801102620
1 54921
2 763519200708
32767 65535
2 372538355074
2 3
2 222581721730
275 855
2 801...

output:

0
763484249040
124179451691
221516737415
798633910227
662903560081
698744257672
585095269006
3428780...

result:

ok 10 tokens

Test #2:

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

input:

10
2 510345505034
2 8361
2 462233945799
76789 68116
2 473308514969
91660 80
2 549888590674
22170 361...

output:

255142233111
462221140373
467388285726
549848561730
819880837908
776485372077
383264807681
459153537...

result:

ok 10 tokens

Test #3:

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

input:

10
2 468915735385
7866 19883
2 547058681922
56 74111
2 976732435434
53671 99605
2 548727587189
7992 ...

output:

468832541648
537282527090
976704431045
548651960799
974348037706
396922814025
202642564668
180284578...

result:

ok 10 tokens

Test #4:

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

input:

10
2 903301784015
66861 714
2 218638573638
1931 21017
2 353956523327
24020 743
2 224499761461
9098 1...

output:

902024110332
218514950518
353465418929
202030044734
840184995582
743785200831
154290481784
864118088...

result:

ok 10 tokens

Test #5:

score: 5
Accepted
time: 591ms
memory: 1148kb

input:

10
16 85551
11 6799 8 9764 52638 350 7964 41396 656 40611 6 1434 12 982 11 12
16 38804
100 31159 123...

output:

58167
25521
54619
22271
14879
16352
58463
17596
42942
47866

result:

ok 10 tokens

Test #6:

score: 5
Accepted
time: 658ms
memory: 1152kb

input:

10
16 25925
47 11 58 61 7817 170 2 14 5471 20 412 7448 848 89 2886 11
16 50578
14 8425 4601 200 3 89...

output:

11213
27243
12567
21067
13597
30001
18574
31213
67638
11517

result:

ok 10 tokens

Test #7:

score: 5
Accepted
time: 576ms
memory: 1148kb

input:

10
16 76053
16 1921 57123 231 6 81085 1587 29460 30 34654 9 3 16 607 8471 197
16 11087
8477 86 563 9...

output:

47186
5460
13881
25098
66487
23466
17290
15800
14966
40653

result:

ok 10 tokens

Test #8:

score: 5
Accepted
time: 590ms
memory: 1152kb

input:

10
16 28433
6310 586 31 134 9559 84532 55929 217 79180 17 17 15 5 19 13 8692
16 37103
93322 14 17 11...

output:

17949
22367
30656
30102
37801
6348
27234
28121
26401
41982

result:

ok 10 tokens

Test #9:

score: 5
Accepted
time: 2ms
memory: 1152kb

input:

10
8 433558825697
91 213 171 378 343 179 50 96
10 579007771223
269 143 139 157 26 141 66 249 6 3
8 3...

output:

407388769565
363453963681
292778208520
109133605000
461478932946
238004216265
864213671655
230894430...

result:

ok 10 tokens

Test #10:

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

input:

10
10 479477542548
185 251 225 182 182 67 48 13 19 3
9 862954297977
232 338 126 365 152 41 183 38 5
...

output:

272781758191
642711821322
540626306890
861668622090
388613469478
596315115720
472821119751
616948594...

result:

ok 10 tokens

Test #11:

score: 5
Accepted
time: 3ms
memory: 1148kb

input:

10
9 533858968262
151 71 308 3 375 127 220 140 65
9 140759885380
257 146 353 316 270 56 20 230 3
8 2...

output:

336082264987
86245602296
228299495811
125235979051
871463022587
517601844707
225912160626
1524851831...

result:

ok 10 tokens

Test #12:

score: 5
Accepted
time: 3ms
memory: 1148kb

input:

10
8 876141876714
117 53 343 232 220 101 226 379
9 641448440848
201 370 58 231 367 369 77 21 4
9 386...

output:

828132055398
443680952762
326417804837
305575832695
554908422818
748569597667
354255407291
388029898...

result:

ok 10 tokens

Test #13:

score: 5
Accepted
time: 5ms
memory: 1152kb

input:

10
9 412233778564
33 374 346 70 348 318 357 17 4
8 694146660982
361 242 317 212 172 387 98 23
8 3379...

output:

278419605264
642682199639
321390657997
722643846621
383448711871
133498915057
373174217645
776714558...

result:

ok 10 tokens

Test #14:

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

input:

10
8 687471850395
26 144 398 133 387 169 358 215
8 839147920414
391 89 53 215 149 371 376 114
8 8298...

output:

642110441464
793641804493
763691503719
521403120993
347241795632
628166618473
828272775716
112657095...

result:

ok 10 tokens

Test #15:

score: 5
Accepted
time: 862ms
memory: 1148kb

input:

10
16 494337725413
54080 17176 8694 85718 86847 35603 60282 91 16726 48 71 4858 942 6502 82492 82649...

output:

471227943844
226285045861
427605099151
460181891405
160963208277
184947381252
288662576560
366645828...

result:

ok 10 tokens

Test #16:

score: 5
Accepted
time: 826ms
memory: 1148kb

input:

10
16 862931800104
53254 11 48330 1426 42460 56255 25242 4349 9 851 32 50792 89355 32365 92 92661
16...

output:

667810494888
165058763010
296088587513
173216856465
177726656720
514329343308
814159185249
512296315...

result:

ok 10 tokens

Test #17:

score: 5
Accepted
time: 809ms
memory: 1152kb

input:

10
16 165899511623
74052 76574 16 86039 278 51881 38299 723 78357 239 8155 30857 88047 14 91 6520
16...

output:

142963867592
833717424892
126503643794
259337558263
106462865301
236610132937
813979478846
359298844...

result:

ok 10 tokens

Test #18:

score: 5
Accepted
time: 783ms
memory: 1152kb

input:

10
16 535844527329
2223 79598 44972 1594 63453 36350 52608 9295 79229 54515 58570 95651 24806 5659 3...

output:

534828973542
738941319972
835020821639
524535077225
485172490334
413746018230
397080173289
827410247...

result:

ok 10 tokens

Test #19:

score: 5
Accepted
time: 819ms
memory: 1152kb

input:

10
16 966874374328
57815 40817 9717 5018 7811 77157 48237 5276 829 12 65240 4548 90348 13 351 3140
1...

output:

816596789918
509477750748
223641496487
124424174241
365211330142
754990805628
820351648159
971379944...

result:

ok 10 tokens

Test #20:

score: 5
Accepted
time: 754ms
memory: 1152kb

input:

10
16 481368491070
13046 26514 65 97957 184 98 330 19639 55106 39004 17608 80659 8861 698 1486 48855...

output:

464160341012
710642254115
412324901290
263133372043
490222157734
60861393772
129855770224
6585670836...

result:

ok 10 tokens