QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#479142#4278. GCD vs LCMmasterhuangTL 1ms5400kbC++20937b2024-07-15 15:23:022024-07-15 15:23:02

Judging History

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

  • [2024-07-15 15:23:02]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:5400kb
  • [2024-07-15 15:23:02]
  • 提交

answer

#include<bits/stdc++.h>
#define LL long long
#define fr(x) freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);
using namespace std;
const int N=1e5+5;
int T,n,m,a,pr[N];LL S[N],mu[N];bool v[N];
inline void init(int M)
{
	for(int i=2;i<=M;i++)
	{
		if(!v[i]) pr[++pr[0]]=i,mu[i]=-1;
		for(int j=1;j<=pr[0]&&i*pr[j]<=M;j++)
		{
			v[i*pr[j]]=1;if(i%pr[j]==0) break;
			mu[i*pr[j]]=-mu[i];
		}
	}mu[1]=1;
	for(int i=1;i<=M;i++) mu[i]=mu[i-1]+1ll*mu[i]*i*i;
	for(int i=1;i<=M;i++) S[i]=S[i-1]+i;
}
inline LL f(int r,int a)
{
	LL ans=0;int u=min(r,a);
	for(int i=1,j;i<=u;i=j+1) j=r/(r/i),ans+=mu[r/i]*(S[min(j,u)]-S[i-1]);
	return ans;
}

int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);cin>>T;init(N-5);
	while(T--)
	{
		cin>>n>>m>>a;if(n>m) swap(n,m);LL ans=0;
		for(int i=1,j;i<=n;i=j+1) j=min(n/(n/i),m/(m/i)),ans+=S[n/i]*S[m/i]*(f(j,a)-f(i-1,a));
		cout<<ans<<"\n";
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5340kb

input:

2
2 2 1
3 4 2

output:

5
45

result:

ok 2 number(s): "5 45"

Test #2:

score: 0
Accepted
time: 1ms
memory: 5284kb

input:

5
2 8 4
10 2 9
7 8 3
2 5 10
5 2 4

output:

88
135
742
39
39

result:

ok 5 number(s): "88 135 742 39 39"

Test #3:

score: 0
Accepted
time: 1ms
memory: 5344kb

input:

5
17 8 8
27 17 10
38 46 2
37 42 1
46 13 1

output:

4164
43084
548829
385452
61783

result:

ok 5 number(s): "4164 43084 548829 385452 61783"

Test #4:

score: 0
Accepted
time: 1ms
memory: 5280kb

input:

10
73 49 10
9 84 15
22 19 17
83 54 6
30 23 9
97 2 4
28 73 9
26 40 11
97 48 7
49 45 18

output:

2437081
119216
35475
3776013
94357
11907
794038
207296
4053849
928605

result:

ok 10 numbers

Test #5:

score: 0
Accepted
time: 1ms
memory: 5400kb

input:

100
75 26 130
70 18 15
109 93 55
69 196 40
180 90 153
188 82 45
167 130 110
77 68 32
56 157 79
156 174 97
190 42 82
69 107 57
152 57 183
107 156 18
73 177 90
122 5 160
108 192 147
173 157 28
39 25 45
117 191 73
8 2 166
66 18 51
76 12 78
90 181 172
40 24 84
23 158 37
7 124 134
170 171 111
62 200 198
...

output:

733546
306373
19237886
34028538
48568920
44112548
87408560
5156750
14409270
135732487
11858723
10249690
14001574
51643353
31220267
88419
79432066
136817339
186804
92568248
88
273073
164650
49310115
177044
2583670
166176
156075703
28836450
163355481
12190226
2976316
3587981
199736999
20671629
5515762...

result:

ok 100 numbers

Test #6:

score: -100
Time Limit Exceeded

input:

10000
60891 25901 72
66133 58189 144
80100 76127 113
56312 7713 20
15505 43545 83
4224 92681 67
86783 58363 95
40265 24699 18
87356 47123 54
30695 14987 197
52463 10356 157
84648 26368 16
50778 80419 99
46382 49146 34
50613 56280 189
86933 38991 186
80758 7552 90
71787 67827 168
83791 19979 96
46722...

output:

454410093465275548
2705485122034769594
6792940506085892554
34435356702147437
83280855424750523
28001980141909957
4686610150694356661
180484338953162315
3095471755633370023
38666143651557218
53930110736125525
908776499719663271
3046354571627118247
948984591080075271
1482373064064778524
20990612734018...

result: