做招聘网站代理商需要多少钱,什么是网站根目录,网站微信建设运维培训班,南宁网站建设优化排名Problem - C - Codeforces
题目大意#xff1a;给出一个数k#xff0c;每次操作可以选择当前k的一个因数x#xff0c;并令kk-x#xff0c;要求令k变成1#xff0c;且相同的x 出现次数不超过2#xff0c;最大操作次数1000
2k1e9
思路#xff1a;因为每个数的l…Problem - C - Codeforces
题目大意给出一个数k每次操作可以选择当前k的一个因数x并令kk-x要求令k变成1且相同的x 出现次数不超过2最大操作次数1000
2k1e9
思路因为每个数的llowbit肯定是这个数的因数那么我们把k拆成二进制例如15就是1111那么我们先操作3次就可以分别把它变成14,12,8每个x都不会重复
接着再把其变成1只要每次都除以2即可每次使用的因数都是2的幂也不会重复这样两套操作下来相同的因数肯定不会超过2总操作数不超过64
//#include__msvc_all_public_headers.hpp
#includebits/stdc.h
using namespace std;
const int N 1e3 5;
typedef long long ll;
const int INF 0x7fffffff;
int ans[N];
int lowbit(int x)
{return x (-x);
}
void solve()
{int k;cin k;vectorintans;ans.push_back(k);while (lowbit(k) ! k){//令k只剩下最高位的1int temp lowbit(k); k - temp;ans.push_back(k);}while (k ! 1){k 1;ans.push_back(k); }cout ans.size() endl;for (int i 0; i ans.size(); i){cout ans[i] ;}cout endl;
}
int main()
{ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int t;cin t;while (t--){solve();}return 0;
}