← All problemsSign in

Jump A or B

CodeChefRating 1184Open on judge ↗

You are standing on the coordinate $0$ of an integer number line, which extends infinitely in the positive direction. You will make $N$ jumps, each of length either $A$ or $B$ along the **positive axis**. You can decide whether to make a jump of length $A$ or $B$ each time, but you must make exactly $N$ jumps. Is it possible for you to end up at coordinate $M$ after all $N$ jumps? For example,

HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17

CodeSearch Tutor

Hints, not spoilers — it won’t hand over the full solution unless you insist.

voice by Sarvam AI

Sign in to chat with the tutor and save your progress.

Sign in to start