题意:求sum=n/1+n/2+n/3+...+n/n。(n<2^31)
分析:在一定的区间内n/i的值是一定的,因此要跳过这段区间来加速求解。
#pragma comment(linker,"/STACK:1024000000,1024000000")
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <limits.h>
#include <iostream>
#include <algorithm>
#include <queue>
#include <cstdlib>
#include <stack>
#include <vector>
#include <set>
#include <map>
#define LL long long
#define mod 100000000
#define inf 0x3f3f3f3f
#define eps 1e-6
#define N 10000000
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define PII pair<int,int>
using namespace std;
inline LL read()
{
char ch=getchar();LL x=,f=;
while(ch>''||ch<''){if(ch=='-')f=-;ch=getchar();}
while(ch<=''&&ch>=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int main()
{
int n;
int T,cas=;
T=read();
while(T--)
{
n=read();
LL ans=;
for(LL i=,last=;i<=n;i=last+)
{
last=n/(n/i);
ans+=(last-i+)*(n/i);
}
printf("Case %d: %lld\n",cas++,ans);
}
}