#include <stdio.h>
#include <iostream>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
 
long long startNum, endNum;
string ans;
bool flag = false;
 
queue<pair<long longstring>> q;
map<long longint> visited;
 
void BFS()
{
    visited[startNum] = 1;
    q.push({startNum, ""});
    
    while(!q.empty())
    {
        long long num = q.front().first;
        string oper = q.front().second;
        q.pop();
        
        if(num == endNum)
        {
            flag = true;
            ans = oper;
            
            return;
        }
        
        for(int i = 1; i <= 4; i++)
        {
            long long numTemp = num;
            
            // *
            if(i == 1)
            {
                numTemp *= numTemp;
                
                if(visited[numTemp] == 0)
                {
                    visited[numTemp] = 1;
                    q.push({numTemp, oper+"*"});
                }
            }
            // +
            else if(i == 2)
            {
                numTemp += numTemp;
                
                if(visited[numTemp] == 0)
                {
                    visited[numTemp] = 1;
                    q.push({numTemp, oper+"+"});
                }
            }
            // -
            else if(i == 3)
            {
                numTemp -= numTemp;
                
                if(visited[numTemp] == 0)
                {
                    visited[numTemp] = 1;
                    q.push({numTemp, oper+"-"});
                }
            }
            // /
            else if(i == 4)
            {
                if(numTemp == 0)
                {
                    continue;
                }
                
                numTemp /= numTemp;
                
                if(visited[numTemp] == 0)
                {
                    visited[numTemp] = 1;
                    q.push({numTemp, oper+"/"});
                }
            }
        }
    }
}
 
int main(void)
{
//    freopen("B14395_input.txt", "r", stdin);
    
    cin >> startNum >> endNum;
    
    if(startNum == endNum)
    {
        cout << "0" << endl;
        
        return 0;
    }
    
    BFS();
    
    if(flag == true)
    {
        cout << ans << endl;
    }
    else
    {
        cout << "-1" << endl;
    }
    
    return 0;
}
cs

+ Recent posts