【数形结合】Gym - 100923I - Por Costel and the Pairs

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  boys at the party. The -th one has clumsiness level . There ale also  girls at the party. The -th girl has clumsiness level  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 , i.e. girl clumsiness level * boy clumsiness level  . 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  representing the number of tests. The next  lines will contain the number .

Input

The input file perechi3.in will contain the number  representing the number of tests. The next  lines will each contain a single integer .

Output

The output file perechi3.out should have  lines. Line  should hold the answer for the -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;
}
posted @ 2017-01-20 01:58  AutSky_JadeK  阅读(293)  评论(0编辑  收藏  举报
TVアニメ「Charlotte(シャーロット)」公式サイト TVアニメ「Charlotte(シャーロット)」公式サイト