QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#583760 | #5503. Euclidean Algorithm | ticking_away# | ML | 0ms | 3552kb | C++17 | 1004b | 2024-09-22 22:04:45 | 2024-09-22 22:04:47 |
Judging History
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);
}
}
Details
Tip: Click on the bar to expand more detailed information
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