atcoder#ARC109B. [ARC109B] log
[ARC109B] log
Score : points
Problem Statement
Snuke is visiting a shop in Tokyo called 109 to buy some logs. He wants logs: one of length , one of length , , and one of length . The shop has logs in stock: one of length , one of length , , and one of length . Each of these logs is sold for yen (the currency of Japan).
He can cut these logs as many times as he wants after buying them. That is, he can get logs of length from a log of length , where . He can also throw away unwanted logs.
Snuke wants to spend as little money as possible to get the logs he wants. Find the minimum amount of money needed to get logs of length to .
Constraints
Input
Input is given from Standard Input in the following format:
Output
Print the minimum amount of money needed to get logs of length to .
4
3
One way to get the logs he wants with yen is:
- Buy logs of length , , and .
- Cut the log of length into two logs of length each and a log of length .
- Throw away one of the logs of length .
109109109109109109
109109108641970782