请求加强数据
查看原帖
请求加强数据
751881
icypenguin/ll楼主2023/6/20 18:45

用二分过了。

#include <iostream>
#include <cmath>
#define ll long long
using namespace std;
ll n, k, tol = 0;
int main(){
    cin >> n >> k;
    for (ll i = 1; i <= n; i++){
        ll nowl = i;
        ll x = k / nowl;
        if (x == 0){
            break;
        }
        ll nowr;
        ll l = nowl, r = n, ans;
        while (l <= r){
            ll mid = (l + r) / 2;
            if (k / mid < x){
                r = mid - 1;
            }else{
                ans = mid;
                l = mid + 1;
            }
        }
        nowr = ans;
        ll t1 = nowr - nowl + 1, t2 = nowl + nowr;
        ll ans1 = t1 * t2 / 2 * x;
        i = ans;
        tol += ans1;
    }
    cout << n * k - tol << endl;
    return 0;
}
2023/6/20 18:45
加载中...