题意:把一个数n进行拆分,拆分出来大于一的数两两不等,使得拆出来的数可以组成[1, n]间的所有数。求最少拆成多少个数。n <= 1000000000。
@Azrael_Death推荐的水题
拆出来的数越小越好,又要组成所有数,易想到拆分二进制。求n在二进制下的位数即可。
#include<map>
#include<cmath>
#include<cstdio>
#include<queue>
#include<vector>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
inline int read() {
int x = 0, flag = 1; char ch = getchar();
while (ch > '9' || ch < '0') { if (ch == '-') flag = -1; ch = getchar(); }
while (ch <= '9' && ch >= '0') { x = x * 10 + ch - '0'; ch = getchar(); }
return x * flag;
}
#define rep(ii, aa, bb) for (int ii = aa; ii <= bb; ii++)
#define drp(ii, aa, bb) for (int ii = aa; ii >= bb; ii--)
#define ll long long
int main() {
int m; cin >> m;
int cnt = 0;
while (m) m >>= 1, cnt++;
cout << cnt;
return 0;
}