QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#167130 | #5503. Euclidean Algorithm | eikki | WA | 1371ms | 3660kb | C++20 | 822b | 2023-09-07 09:38:47 | 2023-09-07 09:38:48 |
Judging History
answer
#include <iostream>
typedef long long ll;
int main() {
// want y mod y-x to equal gcd(x, y)
// y = d + k(y-x)
// kx+d ky+d
// y' = 1 + k(y' - x')
// kx' + 1 = (k-1)y'
// (mod k-1) x' == -1
// (k-1)a + 1, ka+1
// #(r, k, a) s.t. r(ka + 1) <= n given r, k, a > 0
// now just do it block by block
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
int q;
std::cin >> q;
while (q--) {
int n;
ll cnt = 0;
std::cin >> n;
// one-line possible >=<
for (ll i = 1; i <= n; i = 1 + n/(n/i)) for (ll j = 1;
j <= n/i - 1; j = 1 + (n/i - 1) / ((n/i - 1) / j)) cnt += (1 +
(n / (n/i)) - i) * ((1 + (n/i - 1)/((n/i - 1)/j) - j) * ((n/i - 1)/j));
std::cout << cnt << "\n";
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3596kb
input:
3 2 5 14
output:
1 9 62
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 1371ms
memory: 3660kb
input:
3 29107867360 65171672278 41641960535
output:
526529808500 526529808500 526529808500
result:
wrong answer 1st lines differ - expected: '8921593237533', found: '526529808500'