Recursion

Answer & solution
Official answer: 65536
Step through it (2 calls)
Givens and goal
The recursive functions are bar(1)=0 and bar(n)=1+bar(n/2) otherwise, using C integer division; foo(1)=1 and foo(n)=1+foo(bar(n)) otherwise. Find the smallest positive integer n for which foo(n)=5.
Approach
First identify bar as a floor logarithm, then work backwards through the thresholds for successive foo return values.
Step-by-step solution
1. For positive n, integer division by 2 repeatedly halves n with truncation. If 2^m≤n<2^(m+1), exactly m divisions are needed to reach 1. Hence bar(n)=floor(log₂n).
2. Therefore foo(n)=1+foo(floor(log₂n)) for n>1, with foo(1)=1. A foo call counts one level and continues with its much smaller floor-logarithm argument.
3. Let a_j be the smallest input with return value j. The base is a₁=1. To obtain one extra level, floor(log₂n) must reach at least the smallest input a_j needed for the previous level. The least n with floor(log₂n)=a_j is n=2^(a_j).
4. Thus the successive thresholds are a₁=1, a₂=2, a₃=4, a₄=16, a₅=2^16=65536. Monotonicity of floor(log₂n) and of these level thresholds shows no smaller input can skip ahead to five levels.
5. Verify directly: bar(65536)=16, bar(16)=4, bar(4)=2, bar(2)=1. The foo chain is 65536→16→4→2→1, giving return values 5→4→3→2→1 when read from the outer call inward.
6. The requested integer is 65536. The division is integer division; treating bar as an unrounded real logarithm would not model the code.