zoukankan      html  css  js  c++  java
  • 【数形结合】Gym

    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
    ",(ans<<1)+t);
    	  }
    	return 0;
    }
  • 相关阅读:
    IG GROUP开源RESTdoclet项目
    Visual Studio 2012 Update 1抢先看
    使用 Windows Azure 移动服务将云添加到您的应用
    WMF 3.0 RTM(包含PowerShell 3.0 )业已发布
    Node.js 0.9.2 发布(非稳定版)
    vsftpd 3.0.1 正式版发布
    Piggydb 6.2 发布,个人知识库管理
    Apache Commons Codec 1.7 发布
    Notepad++ 6.1.8 正式版发布
    gWaei 3.6.0 发布,英日词典
  • 原文地址:https://www.cnblogs.com/autsky-jadek/p/6321746.html
Copyright © 2011-2022 走看看