QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#344142#5503. Euclidean Algorithmucup-team1198#ML 0ms0kbC++201.3kb2024-03-03 16:56:462024-03-03 16:56:46

Judging History

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

  • [2024-03-03 16:56:46]
  • 评测
  • 测评结果:ML
  • 用时:0ms
  • 内存:0kb
  • [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

result: