因为这道题的 很大但 很小,我们考虑枚举每个 并求出相应答案。
先将所有盒子编号减一,Pak Chanek 是按顺序取的,Lihmuf 要得分就需要保证其取的 。
然后就是硬推,Lihmuf 拿球会以 次为一次循环,所以只需求解一下前 次即可。
那这个式子就很好列了。
模运算不好搞,换成除法。
这个式子现在看起来还是 的,但是 的取值实际上只有 个,可以直接枚举计算,总复杂度仅有 。
/******************************
- @GavinCQTD / 2026-03-12 08:28:55
- "L. Lihmuf Balling" From Codeforces - COMPFEST 15 - Preliminary Online Mirror (Unrated, ICPC Rules, Teams Preferred)
- # https://codeforces.com/problemset/problem/1866/L
- 2000 ms / 256 MB
******************************/
#include <algorithm>
#include <iostream>
#include <cassert>
#include <numeric>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
ll n,m,ans=1,mx;
int main(){
cin >> n >> m;
for(int k=2;k<=m;k++){
ll cur=0;
ll xval=n/gcd(n,k);
for(int i=0;i<k;i++){
ll x=max((i*n+k)/k,(i*n+(k-1))/(k-1)),y=min((i+1)*n/k,xval);
if(x<=y){
cur += (y-x+1)*((x+y)*k/2-i*n);
}
}
// cerr << k << " " << cur << "\n";
if(cur>mx){
mx = cur;
ans = k;
}
}
cout << ans << "\n";
return 0;
}