题意:
给一个n,求sigma(n/i)|1<=i<=n
思路:
假设n=10
被除数 1 2 3 4 5 6 7 8 9 10
商 10 5 3 2 2 1 1 1 1 1
我们可以通过找到第一个10/i==1和第一个10/i==2的位置来得到有多少个n/i==1
以此类推到sqrt(n)
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<stack>
#include<string>
#include<vector>
#include<map>
#include<set>
using namespace std;
#define lowbit(x) (x&(-x))
typedef long long LL;
const int maxn = 100005;
const int inf=(1<<28)-1;
int main()
{
int Case=0,T;
scanf("%d",&T);
while(T--)
{
int n;
scanf("%d",&n);
int k=sqrt(n);
LL Ans=0;
for(int i=1;i<=k;++i)
{
Ans+=n/i;
if(n/i>(n/(i+1)))
Ans+=(n/i-(n/(i+1)))*i;
}
if(n/k==k) Ans-=k;
printf("Case %d: %lld\n",++Case,Ans);
}
return 0;
}