题意
思路
最多两步解决
1. 一步:
只要满足 ((n^m) < n) 即可一步,只要在第一个mi = 1的地方n也有1 无论如何都可以随便改n得到m
2. 无解的情况:
只要在第一个mi=1的时候n(i) -> n(最高位-1) 没有1 出现肯定无法解决
3. 二步:
类似于 10110 -> 00001
10110 ->
10101 ->
00001
只需要得到第一个mi = 1位置的1就行了
我们需要找到mi第一次出现1的位置i
再找到ni在mi第一次出现1的位置前 最后一次出现1的位置
中间态答案就是 (n ^ (2^(idx))) + 2^(i)
相当于牺牲了一个最后一个idx 而n前面的不变得到了 和mi相同的1
code
#include<iostream>
#include<cstdio>
#include<stack>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<vector>
#define int long long
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define long long
#define PI acos(-1.0)
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int INF = 1e18 + 10;
const int N = 1e5 + 10;
const int M = 1e7 + 10;
const int mod = 1e9 + 7;
int n, m, k, x, now, ans;
int qcal(int a, int b) { int res = 1; while (b) { if (b & 1) res = res * a % mod; b >>= 1; a = a * a % mod; } return res; }
int a[N], b[N];
bool is_prime(int n) { if (n < 2) return false; for (int i = 2; i <= n / i; i++) { if (n % i == 0) { return false; } }return true; }
void gzy()
{
cin >> n >> m;
if((n ^ m) < n)
{
cout << 1 << endl;
cout << n << ' ' << m << endl;
return;
}
int cnt = 0;
int idx = -1; // 最后一次出现1的位置
for(int i = 62;~i;i --)
{
if((n >> i) & 1)
{
cnt ++;
idx = i;
}
if((m >> i) & 1)
{
if(cnt < 2)
{
cout << -1 << endl;
return;
}
else
{
// cout << idx << endl;
// cout << i << endl;
cout << 2 << endl;
cout << n << ' ';
cout << (n ^ (1LL << idx) + (1LL << i)) << ' ';
cout << m << endl;
return;
}
}
}
}
signed main()
{
int _ = 1; cin >> _;
while (_ --) gzy();
return 0;
}
// /**
// * ┏┓ ┏┓+ +
// * ┏┛┻━━━┛┻┓ + +
// * ┃ ┃
// * ┃ ━ ┃ ++ + + +
// * ████━████+
// * ◥██◤ ◥██◤ +
// * ┃ ┻ ┃
// * ┃ ┃ + +
// * ┗━┓ ┏━┛
// * ┃ ┃ + + + +Code is far away from
// * ┃ ┃ + bug with the animal protecting
// * ┃ ┗━━━┓ 神兽保佑,代码无bug
// * ┃ ┣┓
// * ┃ ┏┛
// * ┗┓┓┏━┳┓┏┛ + + + +
// * ┃┫┫ ┃┫┫
// * ┗┻┛ ┗┻┛+ + + +
// */
标签:Solo,const,int,res,mi,long,Break,Version,include
From: https://blog.csdn.net/chunyou_/article/details/136651197