Skip to content

Commit 9edbdaa

Browse files
authored
Merge pull request #1630 from AlgorithmWithGod/0224LJH
[20251210] BOJ / G5 / 무한 수열 2 / 이종환
2 parents 71aaf73 + e715fd8 commit 9edbdaa

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
```java
2+
3+
import java.util.StringTokenizer;
4+
import java.util.*;
5+
import java.io.*;
6+
7+
public class Main {
8+
9+
static long N,P,Q,X,Y,ans;
10+
static HashMap<Long,Long> map = new HashMap<>();
11+
12+
13+
public static void main(String[] args) throws IOException {
14+
init();
15+
process();
16+
print();
17+
18+
}
19+
20+
private static void init() throws IOException{
21+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
22+
StringTokenizer st = new StringTokenizer(br.readLine());
23+
N = Long.parseLong(st.nextToken());
24+
P = Long.parseLong(st.nextToken());
25+
Q = Long.parseLong(st.nextToken());
26+
X = Long.parseLong(st.nextToken());
27+
Y = Long.parseLong(st.nextToken());
28+
29+
30+
31+
}
32+
33+
private static void process() throws IOException {
34+
ans = recursive(N);
35+
36+
37+
}
38+
39+
public static long recursive(long num) {
40+
if (num <= 0)return 1;
41+
if (map.containsKey(num)) return map.get(num);
42+
43+
long newNum1 = num/P - X;
44+
long newNum2 = num/Q - Y;
45+
46+
long nResult = recursive(newNum1) + recursive(newNum2);
47+
map.put(num,nResult);
48+
return nResult;
49+
}
50+
51+
private static void print() {
52+
System.out.println(ans);
53+
}
54+
55+
}
56+
```

0 commit comments

Comments
 (0)