QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#583760#5503. Euclidean Algorithmticking_away#ML 0ms3552kbC++171004b2024-09-22 22:04:452024-09-22 22:04:47

Judging History

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

  • [2024-09-22 22:04:47]
  • 评测
  • 测评结果:ML
  • 用时:0ms
  • 内存:3552kb
  • [2024-09-22 22:04:45]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ill = int64_t;

const int MXN = 1e6 + 7;

ill n;

ill get_rb(ill rem, ill v) {
    return rem/(rem/v)+1;
}

map<ill, ill> dp;
ill calc(ill lim) {
    if(dp.count(lim)) return dp[lim];
    ill l = 1, r;
    ill res = 0;
    while(l<=lim) {
        ill val = lim/l;
        r = min(get_rb(lim, l), lim+1);
        res += val*(r-l);
        l = r;
    }
    return dp[lim]=res;
}

void solve() {
    ill l = 1, r;
    ill res = 0;
    while(l<=n) {
        ill val = calc(n/l-1);
        r = min(get_rb(n, l), n+1);
        res += val*(r-l);
        l = r;
    }
    cout << res;
}

void aft() {
    cout << '\n';
}

void pre() {
    cin >> n;
}

int t_;
void init() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> t_;
}

int main() {
    init();
    for(int i=1; t_;) {
        pre(); solve();
        if(++i<=t_) aft();
        else exit(0);
    }
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3552kb

input:

3
2
5
14

output:

1
9
62

result:

ok 3 lines

Test #2:

score: -100
Memory Limit Exceeded

input:

3
29107867360
65171672278
41641960535

output:

8921593237533
21300450379732
13136180138425

result: