数据量这么大直接挨个来肯定是不行的。得想办法减少重复的计算。这样对于每个相等的n/i的i,只需要统计有多少个,而不需要挨个枚举。方法是,设n/i=u,这样i是得到u的最后一个,n/(u+1)+1是得到u的第一个,这样这段区间的和是区间长度*u。
// Created by Chenhongwei in 2015.
// Copyright (c) 2015 Chenhongwei. All rights reserved.
#include"iostream"
#include"cstdio"
#include"cstdlib"
#include"cstring"
#include"climits"
#include"queue"
#include"cmath"
#include"map"
#include"set"
#include"stack"
#include"vector"
#include"sstream"
#include"algorithm"
using namespace std;
typedef long long ll;
int main()
{
//ios::sync_with_stdio(false);
// freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int T;
cin>>T;
while(T--)
{
ll n;
cin>>n;
if(n<=0)
{
cout<<'0'<<endl;
continue;
}
ll ans=n,pre=n;
for(ll i=2;i<=n;i++)
{
ll tmp=n/i;
ans+=tmp;
if(pre!=tmp)
{
ans+=(n/tmp-i)*tmp;
i=n/tmp;
pre=tmp;
}
}
cout<<ans<<endl;
}
return 0;
}