QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#76972 | #5503. Euclidean Algorithm | skittles1412 | AC ✓ | 1883ms | 3480kb | C++17 | 1.6kb | 2023-02-12 23:55:55 | 2023-02-12 23:57:21 |
Judging History
answer
#include "bits/extc++.h"
using namespace std;
template <typename T>
void dbgh(const T& t) {
cerr << t << endl;
}
template <typename T, typename... U>
void dbgh(const T& t, const U&... u) {
cerr << t << " | ";
dbgh(u...);
}
#ifdef DEBUG
#define dbg(...) \
cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]" \
<< ": "; \
dbgh(__VA_ARGS__)
#else
#define cerr \
if (false) \
cerr
#define dbg(...)
#endif
#define endl "\n"
#define long int64_t
#define sz(x) int(std::size(x))
void solve() {
auto s2 = [&](long n) -> long {
long ans = 0, sn = min(n, long(sqrt(n)) + 2);
for (int i = 1; i <= sn; i++) {
ans += long(double(n) / i);
}
for (int i = 1; i <= sn; i++) {
long ql = max(sn, long(double(n) / (i + 1))), qr = long(double(n) / i);
ans += max(long(0), i * (qr - ql));
}
return ans;
};
long n;
cin >> n;
long ans = 0, sn = min(n, long(cbrt(n)));
for (int c = 1; c <= sn; c++) {
ans += s2(long(double(n - c) / c));
}
for (int i = 1; i <= n / sn + 2; i++) {
for (int j = i;; j += i) {
long cans = long(double(n) / (j + 1)) - sn;
if (cans < 0) {
break;
}
ans += cans;
}
}
cout << ans << endl;
}
int main() {
cin.tie(nullptr);
cin.exceptions(ios::failbit);
ios_base::sync_with_stdio(false);
int tcs;
cin >> tcs;
while (tcs--) {
solve();
}
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3404kb
input:
3 2 5 14
output:
1 9 62
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 1076ms
memory: 3416kb
input:
3 29107867360 65171672278 41641960535
output:
8921593237533 21300450379732 13136180138425
result:
ok 3 lines
Test #3:
score: 0
Accepted
time: 1837ms
memory: 3404kb
input:
3 90076809172 100000000000 99913139559
output:
30192292781431 33790187414013 33758574429172
result:
ok 3 lines
Test #4:
score: 0
Accepted
time: 1883ms
memory: 3440kb
input:
3 99997992652 99832769119 99997176887
output:
33789456663124 33729325483151 33789159765448
result:
ok 3 lines
Test #5:
score: 0
Accepted
time: 638ms
memory: 3480kb
input:
30 500000004 991026973 875910473 804967563 817240034 859023503 871905363 994897763 533952899 999999996 500000003 851714124 618161807 500000002 500000000 642565501 703104463 520948789 513785485 999999997 1000000000 579195816 999999998 965942980 870891922 571793533 723494232 999999999 590539561 500000...
output:
106931694901 226252654431 197658605222 180202748830 183212809398 193491469207 196669619643 227219558906 114922441260 228494567273 106931693908 191690034392 134938724588 106931693896 106931693226 140788123843 155385451308 111856217326 110170204124 228494567397 228494568703 125643111389 228494567464 2...
result:
ok 30 lines
Test #6:
score: 0
Accepted
time: 360ms
memory: 3368kb
input:
3000 684920 881740 317776 310160 23336 999832 819596 973868 166 449876 290325 912538 999939 282224 600310 448121 816943 972518 895590 612220 349205 52931 999880 267637 549817 513310 182 852220 314635 377356 96591 628319 999757 597508 896048 116 71393 735158 203 282 68 33305 762621 745035 922434 5853...
output:
67611341 90223986 28005207 27233331 1319648 104127915 83003612 101051578 2569 41769873 25235715 93827427 104140754 24424464 58142642 41582414 82697155 100892535 91843138 59465231 31217321 3478468 104133259 22974376 52576328 48594603 2923 86785163 27686009 34130245 7039269 61257408 104119319 57832117...
result:
ok 3000 lines