QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#344142 | #5503. Euclidean Algorithm | ucup-team1198# | ML | 0ms | 0kb | C++20 | 1.3kb | 2024-03-03 16:56:46 | 2024-03-03 16:56:46 |
answer
#include <map>
#include <set>
#include <array>
#include <cmath>
#include <deque>
#include <bitset>
#include <random>
#include <string>
#include <vector>
#include <cassert>
#include <complex>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define int int64_t
const int MAXN = 1.9e6;
int32_t mem[MAXN];
int f(int n) {
if (n < MAXN) return mem[n];
int ans = 0;
for (int i = 1; i <= n; ++i) {
int c = n / i;
int j = n / c;
ans += c * (j - i + 1);
i = j;
}
return ans;
}
int g(int n) {
int ans = 0;
for (int i = 1; i <= n; ++i) {
/// cerr << i << endl;
int c = n / i;
int j = n / c;
ans += f(c - 1) * (j - i + 1);
i = j;
}
return ans;
}
void solve() {
int n;
cin >> n;
cout << g(n) << "\n";
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
for (int i = 1; i < MAXN; ++i) {
for (int j = i; j < MAXN; j += i) {
mem[j]++;
}
}
for (int i = 1; i < MAXN; ++i) {
mem[i] += mem[i - 1];
}
/// cerr << mem[MAXN - 1];
int tst;
cin >> tst;
while (tst--) {
solve();
}
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