开全局变量爆零,不开就ac,附上ac代码:(ps:wa的代码就是把那几个变量全部放在外面)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ll n, k, l, r, res;
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
cin >> n >>k;
res = n * k;
l = 1;
for(l; l <= n; l = r + 1)
{
if(k/l == 0)break;
r = min(k/(k/l),n);
res -= (ll)(k/l)*(r - l + 1)*(r + l)/2;
}
cout << res << endl;
}