题解 | #x?y?n!#
比赛安排(PDF题面存放于本题)
https://ac.nowcoder.com/acm/contest/120562/A
F题题解:
按位异或相当于不进位的加法或者不退位的减法
x+y>=x^y>=x-y
题目分析:
题目条件要求x^y最小,因为x^y>=x-y,所以x^y最小时就等于x-y。因为x,y都是n的倍数,且gcd(x,y)=n,所以x-y最小等于n,即x^y最小等于n;
此时只需要找到x,y满足x^y=n即可满足题意
因为n<2^31,所以n最多有31位,将n向左移31位(相当于n*2^31)得到x。所以y=x+n;
例如:n:11001
x:1100100000
y:1100111001
代码演示:
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
const int N = 500010;
void solve(){
int n;
cin>>n;
int x=n<<31;
int y=(n<<31)+n;
cout<<x<<" "<<y<<endl;
}
signed main(){
ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
int T=1;cin>>T;
while(T--){
solve();
}
return 0;
}