QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#167130#5503. Euclidean AlgorithmeikkiWA 1371ms3660kbC++20822b2023-09-07 09:38:472023-09-07 09:38:48

Judging History

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

  • [2023-09-07 09:38:48]
  • 评测
  • 测评结果:WA
  • 用时:1371ms
  • 内存:3660kb
  • [2023-09-07 09:38:47]
  • 提交

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";
    }
}

详细

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'