分治法
/* author:jxy lang:C/C++ university:China,Xidian University **If you need to reprint,please indicate the source** */ #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> using namespace std; int org[10001]; int f(int now) { if(now>10000) return f(now>>1)+1; if(org[now])return org[now]; return org[now]=f(now>>1)+1; } int main() { int n; memset(org,0,sizeof(org)); org[1]=1; while(~scanf("%d",&n)) { printf("%d\n",f(n)); } }