We start with 0 and we have to reach n
We can perform 3 operations:
Multiply the current number by 2 (cost p)
Multiply the current number by 3 (cost q)
Increase/Decrease the current number by 1 (cost r)
Find the min-cost to reach from 0 to n
Constraints:
10 testcases
1 <= n <= 10^18
1 <= p,q,r <= 10^9
Example:
n,p,q,r = 11,1,2,8
Answer : 20
Order: +1, *3, *2, *2, -1 = 8 + 2 + 1 + 1 + 8 = 20