算法竞赛入门经典 正整数序列
/*
Name: 正整数序列
Copyright: 刘汝佳
Author: Analyst
Date: 01/03/14 12:10
Description: dev-cpp 5.5.3
*/
#include <stdio.h>
int f(int n)
{
return n == 1 ? 1 : f(n/2)+1; // n/2折半砍
}
int main()
{
int n;
while (scanf("%d", &n) == 1)
printf("%d\n", f(n));
return 0;
}
ps:
自己笔画一下,得出对半折最快。