1037A - Packets(二进制想法)

1037A - Packets

A. Packets

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

You have nn coins, each of the same value of 11.

Distribute them into packets such that any amount xx (1≤x≤n1≤x≤n) can be formed using some (possibly one or all) number of these packets.

Each packet may only be used entirely or not used at all. No packet may be used more than once in the formation of the single xx, however it may be reused for the formation of other xx's.

Find the minimum number of packets in such a distribution.

Input

The only line contains a single integer nn (1≤n≤1091≤n≤109) — the number of coins you have.

Output

Output a single integer — the minimum possible number of packets, satisfying the condition above.

Examples

input

Copy

6

output

Copy

3

input

Copy

2

output

Copy

2

Note

In the first example, three packets with 11, 22 and 33 coins can be made to get any amount xx (1≤x≤61≤x≤6).

  • To get 11 use the packet with 11 coin.
  • To get 22 use the packet with 22 coins.
  • To get 33 use the packet with 33 coins.
  • To get 44 use packets with 11 and 33 coins.
  • To get 55 use packets with 22 and 33 coins
  • To get 66 use all packets.

In the second example, two packets with 11 and 11 coins can be made to get any amount xx (1≤x≤21≤x≤2).

题意:给出一个数n,问最少多少个数可以组成从1到n的所有数。

反思:首先反思一下自己吧,最近学习的态度确实是不够端正的,状态也不是很好,都是致命的问题,但是我却一直没有注意。导致这场第一个题都没有A。最近要积极调整状态吧。

思路:可以扩展想到二进制的想法。那么就是从2^0开始到2^x使得期间的和大于给定的n即可

可行性分析:

不难发现必然是等比数列表示的数最多,而等比数列表现数的数量则为(k-1)logk(n)其中k为等比数列的公倍数,n为数列的长度,然后,证明如下。

AC代码:

#include<cstdio>
#include<cmath>
#include<iostream>
using namespace std;
typedef long long LL;
int main()
{
	LL n;
	scanf("%lld",&n);
	LL l=1,r=32;
	LL ans;
	while(l<=r)
	{
		LL mid=(l+r)/2;
		if(pow(2,mid)-1>=n)
		{
			ans=mid;
			r=mid-1;
		}
		else l=mid+1;
	}
	cout<<ans<<endl;
}

 

转载于:https://www.cnblogs.com/fly-white/p/10092725.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值