#P13815. [CERC 2022] Skills in Pills

[CERC 2022] Skills in Pills

题目描述

An unnamed protagonist of this task received amazing e-mail offers for wondrous pills that will enhance their cognitive and all other sorts of abilities. After carefully analysing all offers and side effects, he has decided that he will order 2 types of pills, let's call them AA and BB. He needs to take pill AA every kk days and pill BB every jj days. He will follow this meticulously over the next nn days.

More formally, in the next nn days, there should be no kk consecutive days where he does not take pill AA and no jj consecutive days where pill BB is not taken. However, there is a twist – the two pills are highly potent and must not be taken on the same day, lest horrible side effects should happen. Given this constraint, what is the smallest number of pills that he needs to take to meet these requirements?

输入格式

You are given three space-separated integers, kk, jj, and nn.

输出格式

Print one number – the minimum number of pills that need to be taken. It is easy to prove that a solution always exists for the given constraints.

2 3 8
6
2 3 11
9
3 7 100
48

提示

Comment

In the first case, we can take pill AA on days 22, 44, 55, and 77, and pill BB on days 33 and 66, giving the sequence .ABAABA\text{.ABAABA}. In the second case, the best approach is to take pills in sequence .ABAABAABA\text{.ABAABAABA}, which requires taking 99 pills.

Input limits

  • 2n1062 \leq n \leq 10^6
  • 2k,jn2 \leq k, j \leq n