시간 제한메모리 제한제출정답맞힌 사람정답 비율
3 초 2048 MB87787.500%

문제

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 $E$. The song plays a beat exactly every $N$ milliseconds. His first jump launches at time $0$, perfectly in sync with the music. As long as his energy $E$ is strictly positive ($E>0$), each jump lasts exactly $E$ milliseconds. When his energy runs out with $E=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$ energy from sheer enjoyment. But if he’s even slightly off-beat, his energy drops by $1$.

입력

The input consists of:

  • One line with two integers $N, E$, the number of milliseconds between beats and the initial energy level of the lead singer. These will satisfy $1 \leq N \leq 3 \cdot 10^5$ and $1 \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.

예제 입력 1

7 9

예제 출력 1

59

예제 입력 2

7 4

예제 출력 2

infinity

예제 입력 3

100001 123123123

예제 출력 3

7581167638793024

출처

ICPC > Regionals > Europe > Northwestern European Regional Contest > Nordic Collegiate Programming Contest > NCPC 2025 J번

  • 문제를 만든 사람: Nils Gustafsson