Given a number n in one move you can either divide it by 5(if n%5==0) or subtract it by 3. You need to determine the minimum number of moves to make the n equal to 2, if this is not possible print -1.
It was a simple dp problem where first you would precompute all the answers and then if answer is infinity then print no else print the answer.
Check if the i-th number is infinity then move to the next number otherwise compute the answer for i for i*5 and i+3 and store the minimum one.
using namespace std;
ans[i] = 1e9;
ans = 0;
ans[i*5] = min(ans[i*5], ans[i] + 1);
ans[i+3] = min(ans[i+3], ans[i] + 1);
if(ans[x] == 1e9)