• 【数形结合】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;
    }
  • 相关阅读:
    前端与算法 leetcode 28.实现 strStr()
    前端与算法 leetcode 27.移除元素
    npm钉钉脚手架,支持考勤信息获取
    VSCode 使用Settings Sync同步配置(最新版教程,非常简单)
    VSCode 远程开发(带免密)
    vscode保存代码,自动按照eslint规范格式化代码设置
    matplotlib 3D数据-【老鱼学matplotlib】
    matplotlib等高线图-【老鱼学matplotlib】
    matplotlib柱状图-【老鱼学matplotlib】
    matplotlib散点数据-【老鱼学matplotlib】
  • 原文地址:https://www.cnblogs.com/autsky-jadek/p/6321746.html
Copyright © 2020-2023  润新知