Solution
如果直接正向处理,会有大数处理,有可能要高精度。但是我们可以发现,操作 等价为 的高精度版,这样可以去掉高精度。
我们还可以发现,如果保持 ,那么进行操作 ,然后进行 ,等价于把 变成 , 变成原来的一半。
因为这组操作要求 , 为奇数,所以要在操作之前把 , 变为奇数,继续进行操作。
总操作次数大概是 ,加上变为奇数的操作(不可能大于 , 没那么大),不会大于 。
Code
code
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef char ch;
typedef string str;
typedef double db;
typedef __int128 i128;
const ll inf=9e18;
const i128 Inf=1e35;
ll a,b,cnt;
bool fl;
vector<str> vec;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>a>>b;
while(a%2==0) a/=2,vec.push_back("B+=B\n");
while(b%2==0) b/=2,vec.push_back("A+=A\n");
if(a<b) swap(a,b),fl=1;
while(a-b>0)
{
a+=b;
vec.push_back((fl?"B+=A\n":"A+=B\n"));
while(a%2==0)
{
a/=2;
vec.push_back((fl?"A+=A\n":"B+=B\n"));
}
if(a<b) swap(a,b),fl=!fl;
}
cout<<vec.size()<<"\n";
for(str s:vec) cout<<s;
}