QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#77778#5503. Euclidean AlgorithmXKErrorML 0ms0kbC++837b2023-02-15 16:29:192023-02-15 16:29:23

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-15 16:29:23]
  • 评测
  • 测评结果:ML
  • 用时:0ms
  • 内存:0kb
  • [2023-02-15 16:29:19]
  • 提交

answer

#include <bits/stdc++.h>

#define maxn 1200005
#define ll long long

using namespace std;

ll n;
int d[maxn];

ll ds(ll x) {
	if (x < maxn) return d[x];
	ll res = 0;
	for (ll l = 1, r; l <= x; l = r + 1) {
		r = x / (x / l);
		res += x / l * (r - l + 1);
	}
	return res;
}


int main() {
//	cout<<(sizeof d) / 1024 / 1024<<endl;
	int T;
	scanf("%d", &T);
	for (int i = 1; i < maxn; i++) {
		for (int j = i; j < maxn; j += i) {
			++d[j];
		}
		d[i] += d[i - 1];
	}
	while (T--) {
		scanf("%lld", &n);
		ll res = 0, lst = 0;
//		int T = 0;
		for (ll l = 1, r; l <= n; l = r + 1) {
//			++T;
			r = n / (n / l);
//			if (T % 1000 == 0) cout<<T<<":"<<l<<" "<<r<<" "<<r - l<<endl;
			ll now = ds(r - 1);
			res += (now - lst) * (n / l);
			lst = now;
		}
		printf("%lld\n", res);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Memory Limit Exceeded

input:

3
2
5
14

output:

1
9
62

result: