UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#205350#3681. 数数snow_trace1002ms1196kbC++11810b2024-07-03 10:20:292024-07-03 13:05:11

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,p;
signed main(){
	srand(time(0));
	cin >> n >> p;
	int res =0 ;
//	if(p>n)swap(p,n);
	if(p>=n){
		cout << n*n << endl;return 0;
	}
	//先处理 j<=p 的情况,这个时候不管怎么做都成立
	int ans = p*n;
	// j>p,拆成两段做
	for(int l = p+1,r;l<=n;l = r+1){
		int k = n/l;r = n/k;
		ans+=(p+1)*(r-l+1)*k;
	}
//	cout << ans <<endl;
	//第二段,没有取满,可以在段内做一下二分
	for(int l = p+1,r;l<=n;l = r+1){
		int k = n/l;r = n/k;
		int ll = l,rr = r+1;
		while(ll<rr){
			int mid = ll+rr>>1;
			if(n-k*mid+1<p+1)rr = mid;
			else ll = mid+1;
		}
		ans+=(rr-l)*(p+1)+(n+1)*(r-rr+1)-k*((r+rr)*(r-rr+1)/2);
	}
	ans-=(n-p);
	cout << ans<<endl;
	return 0;
}
/*
13 0 
*/

Details

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

Test #1:

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

input:

1 1

output:

1

result:

ok single line: '1'

Test #2:

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

input:

31 5

output:

517

result:

ok single line: '517'

Test #3:

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

input:

314 38

output:

41794

result:

ok single line: '41794'

Test #4:

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

input:

539 90

output:

150491

result:

ok single line: '150491'

Test #5:

score: 5
Accepted
time: 1ms
memory: 1196kb

input:

821 7

output:

39424

result:

ok single line: '39424'

Test #6:

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

input:

999 101

output:

372269

result:

ok single line: '372269'

Test #7:

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

input:

51394 884

output:

254200539

result:

ok single line: '254200539'

Test #8:

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

input:

73285 9048

output:

2284525187

result:

ok single line: '2284525187'

Test #9:

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

input:

83540 71982

output:

6912143697

result:

ok single line: '6912143697'

Test #10:

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

input:

91702 38751

output:

6956976179

result:

ok single line: '6956976179'

Test #11:

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

input:

98744 579

output:

383275156

result:

ok single line: '383275156'

Test #12:

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

input:

100000 81256

output:

9824340604

result:

ok single line: '9824340604'

Test #13:

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

input:

16783055 11248

output:

1676846514156

result:

ok single line: '1676846514156'

Test #14:

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

input:

23788812 11482773

output:

490018843274547

result:

ok single line: '490018843274547'

Test #15:

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

input:

28991235 2598253

output:

287143224405440

result:

ok single line: '287143224405440'

Test #16:

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

input:

30000000 21598713

output:

864709192572459

result:

ok single line: '864709192572459'

Test #17:

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

input:

559735984 35972

output:

226105546058176

result:

ok single line: '226105546058176'

Test #18:

score: 5
Accepted
time: 1ms
memory: 1192kb

input:

735930159 342652976

output:

463619025229913519

result:

ok single line: '463619025229913519'

Test #19:

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

input:

923496782 943613

output:

7371463243021065

result:

ok single line: '7371463243021065'

Test #20:

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

input:

1000000000 812581903

output:

982437228552158344

result:

ok single line: '982437228552158344'