1 条题解

  • 0
    @ 2025-11-27 10:30:44
    • 神奇的根号算法:数论分块
    • 时间复杂度:O(n)O(\sqrt{n})
    // 数论分块
    // OI Wiki: https://oiwiki.org/math/number-theory/sqrt-decomposition/
    #include <bits/stdc++.h>
    using namespace std;
    
    using i64 = long long;
    
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(0); cout.tie(0);
    
        i64 T, n;
        cin >> T;
        while (T--) {
            cin >> n;
            i64 ans = 0;
            for (i64 l = 1, r; l <= n; l = r + 1) {
                // [l, r] 范围内的商都是 n / l
                r = n / (n / l);
                ans += n / l * (r - l + 1);
            }
            cout << ans << '\n';
        }
        return 0;
    }
    
    • 1

    信息

    ID
    190
    时间
    500ms
    内存
    32MiB
    难度
    3
    标签
    递交数
    59
    已通过
    32
    上传者