首页 > 其他 > 详细

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

时间:2017-01-20 07:21:37      阅读:419      评论:0      收藏:0      [点我收藏+]

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;
}

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

原文:http://www.cnblogs.com/autsky-jadek/p/6321746.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!