QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#77768#5503. Euclidean AlgorithmXKErrorTL 23ms7464kbC++730b2023-02-15 16:17:562023-02-15 16:17:58

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:17:58]
  • 评测
  • 测评结果:TL
  • 用时:23ms
  • 内存:7464kb
  • [2023-02-15 16:17:56]
  • 提交

answer

#include <bits/stdc++.h>

#define maxn 1000005
#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 / (double)(l));
		res += x / (double)(l) * (r - l + 1);
	}
	return res;
}


int main() {
	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;
		for (ll l = 1, r; l <= n; l = r + 1) {
			r = n / (n / (double)(l));
			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: 100
Accepted
time: 23ms
memory: 7464kb

input:

3
2
5
14

output:

1
9
62

result:

ok 3 lines

Test #2:

score: -100
Time Limit Exceeded

input:

3
29107867360
65171672278
41641960535

output:


result: