A11996 | Packets
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You have $n$ coins, each of the same value of $1$ .
Distribute them into packets such that any amount $x$ ( $1 \leq x \leq 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.
Distribute them into packets such that any amount $x$ ( $1 \leq x \leq 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.
输入格式
The only line contains a single integer $n$ ( $1 \leq n \leq 10^9$ ) — the number of coins you have.
输出格式
Output a single integer — the minimum possible number of packets, satisfying the condition above.
输入输出样例
输入 #1
6
输出 #1
3
输入 #2
2
输出 #2
2
In the first example, three packets with $1$ , $2$ and $3$ coins can be made to get any amount $x$ ( $1\leq x\leq 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$ coins
- To 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\leq x\leq 2$ ).
- 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$ coins
- To 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\leq x\leq 2$ ).
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted