\(\lfloor \frac{n}{l} \rfloor = \lfloor \frac{n}{l + 1} \rfloor = ... = \lfloor \frac{n}{r} \rfloor\)
\(\lfloor \frac{n}{l} \rfloor \le \frac{n}{r} < \lfloor \frac{n}{l} \rfloor + 1\)
根据不等式左侧,得到 \(r \le \lfloor \frac{n}{\lfloor \frac{n}{l} \rfloor} \rfloor\)
例题:https://www.luogu.com.cn/problem/UVA11526
#include<bits/stdc++.h>
using namespace std;
using LL = long long;
void solve(){
LL n;
cin >> n;
LL ans = 0;
for (LL i = 1, j; i <= n; i = j + 1){
j = n / (n / i);
ans += (LL)(j - i + 1) * (n / i);
}
cout << ans << "\n";
}
int main(){
ios::sync_with_stdio(false);cin.tie(0);
int T;
cin >> T;
while (T -- ){
solve();
}
return 0;
}