-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBAEKJOON_14395
More file actions
65 lines (53 loc) · 1.88 KB
/
BAEKJOON_14395
File metadata and controls
65 lines (53 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import java.io.*;
import java.util.*;
public class Main {
static long max = 1000000001L;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer st = new StringTokenizer(br.readLine());
long s = Long.parseLong(st.nextToken());
long t = Long.parseLong(st.nextToken());
Queue<Long> q = new LinkedList<>();
Queue<String> qs = new LinkedList<>();
HashSet<Long> set = new HashSet<>();
if(s==t){
bw.write("0");
bw.flush();
bw.close();
System.exit(0);
}
q.add(s);
qs.add("");
set.add(s);
while (!q.isEmpty()) {
long now = q.poll();
String str = qs.poll();
if(now == t){
System.out.println(str);
System.exit(0);
}
if (0 <= now * now && now * now < max && set.contains(now * now) == false) {
set.add(now*now);
q.add(now*now);
qs.add(str+"*");
}
if (0 <= now + now && now + now < max && set.contains(now + now) == false) {
set.add(now+now);
q.add(now+now);
qs.add(str+"+");
}
if (0 <= now - now && now - now < max && set.contains(now - now) == false) {
set.add(now-now);
q.add(now-now);
qs.add(str+"-");
}
if (now!=0 && 0 <= now / now && now / now < max && set.contains(now / now) == false) {
set.add(now/now);
q.add(now/now);
qs.add(str+"/");
}
}
System.out.println(-1);
}
}