神奇的数字(magic)
#include <iostream> #include<cstring> using namespace std; int dp[1000050]; int main() { memset(dp,0x3f3f,sizeof dp); dp[1] = 1; int n; cin>>n; while(n--) { int k; cin>>k; for(int i=1;i<=k;i++) { if(i%3==0) dp[i] = min(dp[i],dp[i/3]+1); if(i%2==0) dp[i] = min(dp[i],dp[i/2]+1); dp[i] = min(dp[i],dp[i-1]+1); } cout<<dp[k]<<endl; } return 0; }