Ugly numbers in hacker blocks

http://ide.codingblocks.com/#/s/21200
https://hack.codingblocks.com/contests/c/452/1271

Your code will work fine. But question asks answer for multiple test cases, so if it gives TLE, precompute your answer in an answer and use it.