perechi3.in / perechi3.out

We don't know how Por Costel the pig arrived at FMI's dance party. All we know is that he did.

The dance floor is hot because Por Costel broke the air conditioner. On the dance floor, the boys and girls are clumsy. There are 【数形结合】Gym - 100923I - Por Costel and the Pairs boys at the party. The 【数形结合】Gym - 100923I - Por Costel and the Pairs-th one has clumsiness level 【数形结合】Gym - 100923I - Por Costel and the Pairs. There ale also 【数形结合】Gym - 100923I - Por Costel and the Pairs girls at the party. The 【数形结合】Gym - 100923I - Por Costel and the Pairs-th girl has clumsiness level 【数形结合】Gym - 100923I - Por Costel and the Pairs as well. Por Costel finds that a pair of a boy and a girl can dance only if the product of their clumsiness levels is at most 【数形结合】Gym - 100923I - Por Costel and the Pairs, i.e. girl clumsiness level * boy clumsiness level 【数形结合】Gym - 100923I - Por Costel and the Pairs . Por Costel thinks that a sack of oats with a slice of leek could make a better dancing pair than the people at this party. Nonetheless, he would like to find out how many pairs (boy, girl) can dance. The input will contain the number 【数形结合】Gym - 100923I - Por Costel and the Pairs representing the number of tests. The next 【数形结合】Gym - 100923I - Por Costel and the Pairs lines will contain the number 【数形结合】Gym - 100923I - Por Costel and the Pairs.

Input

The input file perechi3.in will contain the number 【数形结合】Gym - 100923I - Por Costel and the Pairs representing the number of tests. The next 【数形结合】Gym - 100923I - Por Costel and the Pairs lines will each contain a single integer 【数形结合】Gym - 100923I - Por Costel and the Pairs.

Output

The output file perechi3.out should have 【数形结合】Gym - 100923I - Por Costel and the Pairs lines. Line 【数形结合】Gym - 100923I - Por Costel and the Pairs should hold the answer for the 【数形结合】Gym - 100923I - Por Costel and the Pairs-th test.

Example

Input
11
1
4
5
10
100
99
16
64
49
50
48
Output
1
8
10
27
482
473
50
280
201
207
198

 

让你求n/1+n/2+...+n/n,除法都是整除。

显然就是xy=n这个双曲线的一支与坐标轴形成的区域内,整点的个数,不包含坐标轴上的点,但包含双曲线上的点。

画一条y=x的直线,将这个区域分成两部分,只需要统计一半的区域即可。

细节自己手推一下就好。

复杂度O(sqrt(n))。

#include<cstdio>
#include<cmath>
using namespace std;
typedef long long ll;
int T;
ll n;
int main()
{
	//freopen("i.in","r",stdin);
	freopen("perechi3.in","r",stdin);
	freopen("perechi3.out","w",stdout);
	scanf("%d",&T);
	for(;T;--T)
	  {
	  	ll ans=0;
	  	int cnt=0;
	  	scanf("%I64d",&n);
	  	if(n==1ll)
	  	  {
	  	  	puts("1");
	  	  	continue;
	  	  }
	  	ll x=(ll)sqrt((double)n+0.5);
	  	ll t=0;
	  	for(ll i=1;i<=x;++i)
	  	  if(i*i<=n)
	  	  	++t;
	  	  else
	  	  	break;
	  	if(x*x==n)
	  	  --x;
	  	for(ll i=x;i>0;--i)
	  	  ans+=((n/i)-i);
	  	printf("%I64d\n",(ans<<1)+t);
	  }
	return 0;
}

相关文章: