using
System;
using
System.Collections.Generic;
class
MainClass {
static
string
changeNtoM(
int
N,
int
M)
{
if
(N == M) {
return
" "
;
}
if
(M == 0) {
return
"-"
;
}
Queue<KeyValuePair<
int
,
string
> > q
=
new
Queue<KeyValuePair<
int
,
string
> >();
Dictionary<
int
,
bool
> visited
=
new
Dictionary<
int
,
bool
>();
q.Enqueue(
new
KeyValuePair<
int
,
string
>(N,
""
));
visited[N] =
true
;
q.Enqueue(
new
KeyValuePair<
int
,
string
>(1,
"/"
));
visited[1] =
true
;
while
(q.Count > 0) {
KeyValuePair<
int
,
string
> cur = q.Dequeue();
if
(cur.Key == M) {
return
cur.Value;
}
if
(!visited.ContainsKey(cur.Key + cur.Key)
&& cur.Key + cur.Key <= M) {
q.Enqueue(
new
KeyValuePair<
int
,
string
>(
cur.Key + cur.Key, cur.Value +
"+"
));
visited[cur.Key + cur.Key] =
true
;
}
if
(!visited.ContainsKey(cur.Key * cur.Key)
&& cur.Key * cur.Key <= M) {
q.Enqueue(
new
KeyValuePair<
int
,
string
>(
cur.Key * cur.Key, cur.Value +
"*"
));
visited[cur.Key * cur.Key] =
true
;
}
}
return
"-1"
;
}
public
static
void
Main(
string
[] args)
{
int
N = 7, M = 392;
string
result = changeNtoM(N, M);
if
(result ==
"-1"
)
Console.WriteLine(result);
else
Console.WriteLine(result.Length +
"\n"
+ result);
}
}