{"problem":{"name":"C. Save Energy!","description":{"content":"Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after _k_ minutes after turning on. During cooking, Julia goes to th","description_type":"Markdown"},"platform":"Codeforces","limit":{"time_limit":1000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"CF937C"},"statements":[{"statement_type":"Markdown","content":"Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after _k_ minutes after turning on.\n\nDuring cooking, Julia goes to the kitchen every _d_ minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly.\n\nIt is known that the chicken needs _t_ minutes to be cooked on the stove, if it is turned on, and 2_t_ minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off.\n\n## Input\n\nThe single line contains three integers _k_, _d_ and _t_ (1 ≤ _k_, _d_, _t_ ≤ 1018).\n\n## Output\n\nPrint a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10 - 9.\n\nNamely, let's assume that your answer is _x_ and the answer of the jury is _y_. The checker program will consider your answer correct if .\n\n[samples]\n\n## Note\n\nIn the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for . Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for . Thus, after four minutes the chicken will be cooked for . Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready .\n\nIn the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.","is_translate":false,"language":"English"},{"statement_type":"Markdown","content":"Julia 计划在宿舍的厨房里煮一只鸡。为了节约能源，厨房里的炉子在开启后 #cf_span[k] 分钟会自动关闭。\n\n在烹饪过程中，Julia 每隔 #cf_span[d] 分钟会去一次厨房，如果炉子关闭了，就将其重新打开。当炉子关闭时，食物仍保持温热。炉子的开关是瞬时的。\n\n已知，如果炉子开启，鸡需要 #cf_span[t] 分钟才能煮熟；如果炉子关闭，则需要 #cf_span[2t] 分钟。你需要计算，假设鸡在炉子开启时以恒定速度煮熟，在炉子关闭时也以恒定速度煮熟，那么 Julia 煮熟这只鸡总共需要多少时间。\n\n输入仅一行，包含三个整数 #cf_span[k], #cf_span[d] 和 #cf_span[t]（#cf_span[1 ≤ k, d, t ≤ 1018]）。\n\n请输出一个数字，表示烹饪的总时间（分钟）。相对误差或绝对误差不得超过 #cf_span[10 - 9]。\n\n具体而言，假设你的答案是 #cf_span[x]，标准答案是 #cf_span[y]，当满足 时，判题程序将认为你的答案正确。\n\n在第一个例子中，鸡在开启的炉子上煮了 3 分钟，之后在关闭的炉子上煮了 。接着，鸡在关闭的炉子上又煮了 1 分钟，完成了 。因此，4 分钟后，鸡已经煮了 。在第 5 分钟之前，Julia 重新打开了炉子，再经过 #cf_span[2.5] 分钟，鸡就煮好了。\n\n在第二个例子中，当炉子关闭时，Julia 立即将其打开，因此炉子始终开启，鸡在 20 分钟内煮熟。\n\n## Input\n\n输入仅一行，包含三个整数 #cf_span[k], #cf_span[d] 和 #cf_span[t]（#cf_span[1 ≤ k, d, t ≤ 1018]）。\n\n## Output\n\n请输出一个数字，表示烹饪的总时间（分钟）。相对误差或绝对误差不得超过 #cf_span[10 - 9]。具体而言，假设你的答案是 #cf_span[x]，标准答案是 #cf_span[y]，当满足 时，判题程序将认为你的答案正确。\n\n[samples]\n\n## Note\n\n在第一个例子中，鸡在开启的炉子上煮了 3 分钟，之后在关闭的炉子上煮了 。接着，鸡在关闭的炉子上又煮了 1 分钟，完成了 。因此，4 分钟后，鸡已经煮了 。在第 5 分钟之前，Julia 重新打开了炉子，再经过 #cf_span[2.5] 分钟，鸡就煮好了。在第二个例子中，当炉子关闭时，Julia 立即将其打开，因此炉子始终开启，鸡在 20 分钟内煮熟。","is_translate":true,"language":"Chinese"},{"statement_type":"Markdown","content":"**Definitions**  \nLet $ k, d, t \\in \\mathbb{Z}^+ $ be given integers with $ 1 \\leq k, d, t \\leq 10^{18} $.  \n\nLet the stove cycle be defined as follows:  \n- The stove turns on at time $ 0 $ and remains on for $ k $ minutes.  \n- After $ k $ minutes, it turns off.  \n- Julia checks the stove every $ d $ minutes and turns it on immediately if off.  \n- The chicken requires $ t $ minutes of active stove time (stove on) or $ 2t $ minutes of passive time (stove off) to be fully cooked.  \n\nLet $ r = k \\mod d $. If $ r = 0 $, then $ r = d $.  \n\nDefine one full cycle length:  \n$$\nC = \\begin{cases} \nd & \\text{if } k \\geq d \\\\\nk & \\text{if } k < d \n\\end{cases}\n$$  \nBut more accurately, the **effective cycle** is determined by the recurrence of Julia’s intervention:  \nLet $ C = \\min\\{ x \\in \\mathbb{Z}^+ \\mid x \\geq k \\text{ and } x \\equiv 0 \\pmod{d} \\} $, i.e.,  \n$$\nC = \\left\\lceil \\frac{k}{d} \\right\\rceil \\cdot d\n$$  \n\nWithin one cycle of length $ C $:  \n- Stove is **on** for $ k $ minutes.  \n- Stove is **off** for $ C - k $ minutes.  \n\nLet the cooking rates be:  \n- On: $ \\frac{1}{t} $ per minute.  \n- Off: $ \\frac{1}{2t} $ per minute.  \n\nCooking progress per cycle:  \n$$\np = \\frac{k}{t} + \\frac{C - k}{2t} = \\frac{2k + C - k}{2t} = \\frac{k + C}{2t}\n$$  \n\nLet $ n $ be the number of full cycles needed to reach or exceed 1 unit of cooking:  \n$$\nn = \\left\\lfloor \\frac{1}{p} \\right\\rfloor\n$$  \nRemaining progress after $ n $ cycles:  \n$$\nr_{\\text{rem}} = 1 - n \\cdot p\n$$  \n\nThen simulate the next partial cycle:  \n- First, use the stove-on phase (up to $ k $ minutes) to cover $ r_{\\text{rem}} $.  \n- If not enough, use the stove-off phase.  \n\nLet $ t_{\\text{on}} = \\min\\left(k, r_{\\text{rem}} \\cdot t \\right) $  \nRemaining after on-phase: $ r' = r_{\\text{rem}} - \\frac{t_{\\text{on}}}{t} $  \nLet $ t_{\\text{off}} = \\begin{cases} \nr' \\cdot 2t & \\text{if } r' > 0 \\\\\n0 & \\text{otherwise}\n\\end{cases} $  \n\nTotal time:  \n$$\nT = n \\cdot C + t_{\\text{on}} + t_{\\text{off}}\n$$  \n\n**Constraints**  \n$ 1 \\leq k, d, t \\leq 10^{18} $  \n\n**Objective**  \nCompute total cooking time $ T $ with precision such that relative or absolute error $ \\leq 10^{-9} $.","is_translate":false,"language":"Formal"}],"meta":{"iden":"CF937C","tags":["math"],"sample_group":[["3 2 6","6.5"],["4 2 20","20.0"]],"created_at":"2026-03-03 11:00:39"}}