第十四届华中科技大学程序设计竞赛决赛 B-Trees on Sale 【模拟】【规律】

点击打开链接

首先要有n个1,然后开始从2到m依次判断,记录当前总和,如果不足n捆则向上取整补充,数据范围1e12,虽然很大,但是在高位的是时候可以直接跳过,所以运行速度实际很小,具体实现看代码;

#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ios::sync_with_stdio(false);
    ll n, m;
    while(cin >> n >> m)
    {
        ll sum = n;
        ll i = 2;
        ll num = n;
        while(i <= m)
        {
            if(sum < i * n)
            {
                ll x = sum / i;
                if(n > x)
                {
                    sum += (n - x) * i;
                    num += (n - x);
                }
 
            }
            ll x = sum / n;
            i = x + 1;
        }
        cout << num << endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/head_hard/article/details/80214727