[bzoj1192]鬼谷子的钱袋

来源:互联网 发布:淘宝天猫运营培训 编辑:程序博客网 时间:2024/04/28 00:53

Description

求最少需要多少个数才能组合(+)成1~n的任意数。
n<=10^9

Solution

呵呵呵。
乱逛的时候发现了这一道水题。
小学奥数题。
你要选的数肯定是1,2,4,8….2^k
那么答案就是k+1.
而k就等于log2n+1

Code

#include<cmath>#include<cstdio>using namespace std;int main() {    int n;scanf("%d",&n);    printf("%d",(int)log2(n)+1);}

C++渣代码略长

0 0