codeforce 1037a packets (数论?)【2018.9.2混合场】no.10

Packets

传送
You have n coins, each of the same value of 1.
Distribute them into packets such that any amount x (1≤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 x, however it may be reused for the formation of other x’s.
Find the minimum number of packets in such a distribution.

Input

The only line contains a single integer n(1≤n≤10^9) — the number of coins you have.

Output

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

6

output

3

input

2

output

2

Note

In the first example, three packets with 1, 2 and 3 coins can be made to get any amount x (1≤x≤6).To get 1 use the packet with 1 coin.To get 2 use the packet with 2 coins.To get 3 use the packet with 3 coins.To get 4 use packets with 1 and 3 coins.To get 5 use packets with 2 and 3 coinsTo get 6 use all packets.In the second example, two packets with 1 and 1 coins can be made to get any amount x (1≤x≤2).


题目大意:

读不懂题目系列
好像是有n个硬币,分到x个口袋里,最终使这x个口袋能组成 1~n之间的所有数

做法:

找规律
把这个数拆成2进制,有几位数就需要几个袋子,具体原因:找规律

代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14

#include<cstdio>
using namespace std;
int (){
int n;
cin>>n;
for(int i=1;i<=31;i++){
if((1<<i)>n){
cout<<i<<endl;
break;
}
}
return 0;
}