Fun with Integers -codeforces

读懂题意就好,有个最直接的想法,枚举\(a,b\),复杂度\(O(n^2)\)。然而换成枚举\(a,x\),复杂度\(O(nlg(n))\)\(<a,b>\)\(<b,a>\)的贡献只能算一次。

代码

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

int n;
long long ans;

int main()
{
    cin >> n;
    for (int a = 2; a <= n / 2; ++a) for (int x = 2; x * a <= n; ++x) ans += x * 4;
    cout << ans << endl;

    return 0;
}

猜你喜欢

转载自www.cnblogs.com/zgglj-com/p/9971929.html