Mind the Traps (APCS 2025-06 Beginner)
Points 100 1.0s 256MA simulation game is played on a one-dimensional number line, with the following rules:
- The starting position is \(0\).
- The initial health is \(k\).
- When the current health is \(v\), the character jumps \(v\) cells to the right, i.e. from position \(p\) to \(p + v\).
- After each move, if it lands on a multiple of \(x_1\) or \(x_2\), health is lost:
- If it lands on a multiple of \(x_1\), health decreases by \(y_1\).
- If it lands on a multiple of \(x_2\), health decreases by \(y_2\).
- If it is a multiple of both \(x_1\) and \(x_2\), health decreases by \(y_1 + y_2\) in total.
- When health becomes \(\le 0\), the game ends, and the current position is output.
Input
The first line contains an integer \(k\), the initial health.
The second line contains two integers \(x_1\) and \(y_1\).
The third line contains two integers \(x_2\) and \(y_2\).
Constraints
- \(1 \le k \le 20\)
- \(1 \le x_1, x_2 \le 10\)
- \(1 \le y_1, y_2 \le 20\)
Output
Output the position where the game ends.
Scoring
The time limit for each test case is \(1\) second; your score is the sum over the test cases you pass. The subtasks are:
- Subtask 1 (\(40\) points): \(x_1 = 3\), \(x_2 = 4\), \(y_1 = y_2 = k\).
- Subtask 2 (\(60\) points): no additional constraints.
Sample Input 1
1
3 1
4 1
Sample Output 1
3
Sample Input 2
7
3 2
2 3
Sample Output 2
18
Source
APCS programming exam, June 2025, Problem 1.
Log in to write and submit code.
Log in