题解:P15632 [2019 KAIST RUN Spring] A Plus Equals B
zhuzifengzhuzifeng · · 题解
思路
这道题我们可以发现操作里的
证明
因为每次
代码
#include<bits/stdc++.h>
#define PII pair<int,int>
#define int long long
using namespace std;
const int MAXN=1e6+5;
int a,b,op[MAXN],cnt;
string s[]={"A+=A","A+=B","B+=A","B+=B"};
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
cin>>a>>b;
while(a!=b){
while(a%2==0)a/=2,op[++cnt]=4;
while(b%2==0)b/=2,op[++cnt]=1;
if(a>b)a+=b,op[++cnt]=2;
else if(a<b)b+=a,op[++cnt]=3;
}cout<<cnt<<'\n';
for(int i=1;i<=cnt;i++)cout<<s[op[i]-1]<<'\n';
return 0;
}