#P14504. [NCPC 2025] Jump

[NCPC 2025] Jump

题目背景

:::align{center}

Ballsout at Metal Frenzy Open Air 2022, image by S. Bollmann, commons.wikimedia.org

:::

题目描述

The Unsightly Halfwits are putting on a wild concert in their natural habitat of Húsavík. Their lead singer, Sveinn "Springheel" Jónsson, is leaping about the stage with vigorous energy, turning every note into a spectacle. But keeping in rhythm while bouncing so chaotically is no easy task, and you can’t help but wonder how long he can keep this up.

Sveinn starts with an energy level of EE. The song plays a beat exactly every NN milliseconds. His first jump launches at time 00, perfectly in sync with the music. As long as his energy EE is strictly positive (E>0E>0), each jump lasts exactly EE milliseconds. When his energy runs out with E=0E=0, he collapses and the show is over. If he still has energy after landing, he immediately springs up again for the next jump. When Sveinn lands exactly on a beat, he gains +1+1 energy from sheer enjoyment. But if he's even slightly off-beat, his energy drops by 11.

输入格式

The input consists of:

  • One line with two integers N,EN, E, the number of milliseconds between beats and the initial energy level of the lead singer. These will satisfy 1N31051 \leq N \leq 3 \cdot 10^5 and 1E1091 \leq E \leq 10^9.

输出格式

Output a single integer, the number of milliseconds that will pass before Sveinn stops jumping. If he never stops, instead print infinity\texttt{infinity}.

7 9
59
7 4
infinity
100001 123123123
7581167638793024