How to solve this problem

Revision en1, by ChitreshApte, 2021-07-21 17:20:37

We start with 0 and we have to reach n

We can perform 3 operations:

  1. Multiply the current number by 2 (cost p)

  2. Multiply the current number by 3 (cost q)

  3. 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

Tags number-theory

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English ChitreshApte 2021-07-21 17:20:37 476 Initial revision (published)