LINK TO QUESTION - > http://www.spoj.com/problems/MST1/

```
#include<cstdio>
#define M 20000007
typedef int ull;
inline ull mi(ull a,ull b)
{
if(a>b)
return b;
else
return a;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
ull n;
scanf("%d",&n);
ull *dp=new ull[n+1];
dp[1]=0;
for(ull i=2;i<=n;i++)
{
dp[i]=dp[i-1]+1;
if(i%2==0)
{
dp[i]=mi(dp[i],1+dp[i/2]);
}
if(i%3==0)
{
dp[i]=mi(dp[i],1+dp[i/3]);
}
}
printf("%d\n",dp[n]);
}
return 0;
}
```

here is my solution

i am using dp to solve this

still getting tle

can you please tell me what should be done to optimize this code