## 题意
求
```cpp
long long H(int n){
long long res=0;
for( int i = 1; i <= n; i=i+1 ){
res = (res + n/i);
}
return res;
}
```
的值。
多组数据。
$1\le T\le 10^3,1\le n<2^{31}
分析一下时间复杂度,发现时间复杂度即对于 n,所有的 \lfloor\frac n i\rfloor 的取值数量,可以知道,\lfloor\frac n i\rfloor 可以取得 1,2,\cdot\cdot\cdot,\sqrt n,\lfloor\frac n {\sqrt n}\rfloor,\lfloor\frac n {\sqrt n-1}\rfloor,\cdot\cdot\cdot,n 这 O(\sqrt n) 种取值,即时间复杂度为 O(T\sqrt n)。
注意此题轻微卡常。
代码:
#include<bits/stdc++.h>
using namespace std;
#define int long long
inline int read(){
}
inline int h(int n){
if(!n){
return 0;
}
int res=0,j;
for(register int i=1;i<=n;i=j+1){
j=n/(n/i);
res+=(j-i+1)*(n/i);
}
return res;
}
signed main(){
int t,n;
t=read();
while(t--){
n=read();
printf("%lld\n",h(n));
}
return 0;
}