B
//这个题,傻逼了,明显就是构造一个二进制数,而且二进制数每位是二倍关系,
//联想高中的斐波那契数列的关系,显然有2^n-1+2^n=2^(n+1)-2^(n-1);
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve() {
ll n;
cin >> n;
vector<int> arr(32, 0);
for (int i = 0; i < 30; i++) {
if ((n >> i) &(ll)1) {
if (arr[i] == 1) {
arr[i] = 0;
arr[i + 1] = 1;
} else if (i > 0 && arr[i - 1] == 1) {
arr[i + 1] = 1;
arr[i - 1] = -1;
} else {
arr[i] = 1;
}
}
}
cout << 31 << "\n";
for (int i = 0; i < 31; i++) {
cout << arr[i] << " ";
}
cout << "\n";
}
int main() {
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
B
//这个题,建议打表看性质,bitset是很好用的容器
//正确性说明:由于连续,所以,+1必然是从最低为开始;
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll qmi(ll m, ll k)
{
ll res = 1, t = m;
while (k)
{
if (k&1) res = res * t;
t = t * t;
k >>= 1;
}
return res;
}
int lowbit(ll x) {
return x & -x;
}
void solve() {
ll a,b;
cin>>a>>b;
ll o=a^b;
cout<<(2,lowbit(o))<<"\n";
}
int main() {
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
C
//构造使得 连加s/ki<s化简得到 连加1/ki<1;
//检查k,其实检查最大公倍数>硬币数的连加!!!!!
//ps.我是乱搞出来的
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gggcd(ll a,ll b){
return a*b/(__gcd(a,b));
}
void solve() {
ll n;
cin>>n;
vector<ll> vc(n+1);
ll num=1;
for(int i=1;i<=n;i++){
cin>>vc[i];
num=gggcd(num,vc[i]);
//cout<<vc[i]<<" ";
}
vector<int> ans(n+1);
ll sum=0;
for(int i=1;i<=n;i++){
ans[i]=num/vc[i];
sum+=ans[i];
}
if(sum<num){
for(int i=1;i<=n;i++){
cout<<ans[i]<<" ";
}}else{
cout<<-1;
}
cout<<"\n";
}
int main() {
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
C
//规律不难看出
//但是实现有点屎
//要看出两个东西,1对角交换,(n-i)*2的增量,相邻也是,为零加速,优先用对角,不够就直接i和i+k
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
ll T;
cin >> T;
while (T--) {
int n;
ll k;
cin >> n >> k;
ll max_s = 0;
ll index=n;
for (int i = 1; i <= n; i++) {
max_s+=abs(i-index--);
}
if (k&1 || k > max_s) {
cout << "No\n";
} else {
cout << "Yes\n";
vector<int> p(n);
iota(p.begin(), p.end(), 0); // 初始化排列为 [0, 1, 2, ..., n-1]
k /= 2;
for (int i = 0; k > 0; i++) {
if (k >= n - 1 - 2 * i) {
swap(p[i], p[n - 1 - i]);
k -= n - 1 - 2 * i; //收益
} else {
swap(p[i], p[i + k]);//剩余交换
k = 0;
}
}
for (int i = 0; i < n; i++) {
cout << p[i] + 1 << " ";
}
cout << "\n";
}
}
return 0;
}