对于[k/i]*i,我们可以分两端,前,最多有段,后边从到n,取值范围为1-,所以最多有段,共2*段。对于每段从i开始,其上界j=k/(k/i)(维持k/i不变最大范围i-j)。
计算[k/i]*i时间复杂度降到级别。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
#define LL long long
#define N 10000
const long long mod = 1e9 + 7;
#define rep(i,a,b) for (LL i = a; i <= b; i++)
#define per(i, a, b) for(LL i=a;i>=b;i--)
LL n, k,sum=0;
LL summ(long long x)
{
return x * (x + 1) / 2;
}
int main()
{
cin >> n >> k;
for (LL i = 1, j=1; i <= n; i = j + 1)
{
LL x = k/i;
if (x == 0)
break;
else
j = min(n, k / x);
LL l = summ(j) - summ(i - 1);
sum += l*x;
}
cout <<sum << endl;
return 0;
}