File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed
Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change 1+ ```
2+ import java.io.*;
3+ import java.util.*;
4+
5+ public class Main {
6+ private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+ private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
8+ private static Map<Long, Long> map;
9+ private static int P, Q;
10+ private static long N;
11+
12+ public static void main(String[] args) throws IOException {
13+ init();
14+
15+ long answer = backTracking(N);
16+ bw.write(answer + "\n");
17+ bw.flush();
18+ bw.close();
19+ br.close();
20+ }
21+
22+ private static void init() throws IOException {
23+ StringTokenizer st = new StringTokenizer(br.readLine());
24+ N = Long.parseLong(st.nextToken());
25+ P = Integer.parseInt(st.nextToken());
26+ Q = Integer.parseInt(st.nextToken());
27+
28+ map = new HashMap<>();
29+ }
30+
31+ private static long backTracking(long n) {
32+ if (n == 0) return 1;
33+ if (map.containsKey(n)) return map.get(n);
34+
35+ long temp = backTracking(n/P) + backTracking(n/Q);
36+ map.put(n, temp);
37+ return temp;
38+ }
39+ }
40+ ```
You can’t perform that action at this time.
0 commit comments