Skip to content
Author: lllyouo
Date: 20250702
tag: 约数
link: https://www.luogu.com.cn/problem/P2261

问题描述

link

分析

参考代码

cpp
#include <bits/stdc++.h>
using namespace std;

int main() {
    long long n, k;
    cin >> n >> k;

    long long ans = n * k;
    for (int x = 1, gx; x <= n; x = gx + 1) {
        gx = k / x ? min(k / (k / x), n) : n;
        ans -= (k / x) * (x + gx) * (gx - x + 1) / 2;
    }
    cout << ans << endl;

    return 0;
}