#P16898. [GKS 2022 #H] Magical Well Of Lilies

    ID: 19226 远端评测题 2000ms 1024MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>动态规划 DP2022调和级数Google Kick Start

[GKS 2022 #H] Magical Well Of Lilies

Problem Description

There is a deep magical well in a forest that has some lilies on its waters. You have a large empty basket and some coins, and are standing next to the well. You have more coins than there are lilies in the well. The well has taken note of the fact that your basket is empty.

If you toss 11 coin into the well, the well will toss out 11 lily into your basket. If you toss 44 coins at once into the well, the well will take note of how many lilies it has tossed out into your basket so far. If you toss 22 coins at once into the well, the well will toss out as many lilies into your basket as it had last taken note of. If you toss 11 coin, or 22 coins at once, into the well, and there are not enough lilies left in the well, the well will not toss out any lilies.

Given the number of lilies LL in the well at the beginning, return the minimum number of coins you will need to toss into the well to make it toss all of its lilies into your basket.

Input Format

The 11st line of the input gives the number of test cases, TT. TT lines follow.

Each line contains a single integer LL, representing the number of lilies in the well at the beginning.

Output Format

For each test case, output 11 line containing Case #xx: yy, where xx is the test case number (starting from 11) and yy is the minimum number of coins you will need to toss into the well to make it toss out all of its LL lilies into your basket.

2
5
20
Case #1: 5
Case #2: 15

Hint

For test case #11, when there are 55 lilies in the well, the least number of coins needed is 55. We toss them, 11 at a time, into the well, and the well tosses out the 55 lilies, 11 at a time, into our basket. No other sequence of moves results in a better solution, so 55 is our answer.

For test case #22, first, we toss 55 coins, 11 at a time, into the well, and the well tosses out 55 lilies, 11 at a time, into our basket. Next, we toss 44 coins at once into the well, and the well takes note that it has tossed out 55 lilies into our basket so far. Then, we toss 22 coins at once into the well, and the well tosses out 55 lilies (that it took note of) into our basket. Then, we toss another 22 coins at once into the well, and the well tosses out another 55 lilies into our basket. Finally, we toss another 22 coins at once into the well, and the well tosses out the final 55 lilies into our basket. Total coins needed is 1515. Getting 2020 lilies out of the well is not possible with any lesser number of coins, so 1515 is our answer.

Limits

Test Set 11

1T20.1 \le T \le 20.

1L20.1 \le L \le 20.

Test Set 22

1T100.1 \le T \le 100.

1L105.1 \le L \le 10^5.