Maths WorkshopMaths problems with full solutions
Exercise 1980Calculus › Single-variable calculus › Continuity › Functional equationsOlympiadAdded 5 Nov 2026

Solving f(f(n)) = n + 2 on the positive integers

#functional equation#integers#parity#recursion

Statement

Find all functions f:N∗→N∗f:\mathbb{N}^*\to\mathbb{N}^* (positive integers) such that f(f(n))=n+2f(f(n))=n+2 for all n≥1n\ge1.

Hint

Apply ff to both sides to show that f(n+2)=f(n)+2f(n+2)=f(n)+2. Then everything is determined by f(1)f(1) and f(2)f(2).

Show solutionHide solution

Solution

Step 1: a recursion. Apply ff to f(f(n))=n+2f(f(n))=n+2 and use the equation with nn replaced by f(n)f(n):
f(n+2)=f(f(f(n)))=f(n)+2.f(n+2)=f\bigl(f(f(n))\bigr)=f(n)+2.
Let a=f(1)a=f(1) and b=f(2)b=f(2). Then for k≥1k\ge1:
f(2k+1)=a+2k,f(2k)=b+2k−2.f(2k+1)=a+2k,\qquad f(2k)=b+2k-2.

Step 2: using the equation at n=1n=1. f(a)=3f(a)=3.
- If aa is odd, a=2m+1a=2m+1, then f(a)=a+2m=2a−1f(a)=a+2m=2a-1; setting this equal to 33 gives a=2a=2, which is not odd. Contradiction.
- So aa is even, a=2ma=2m, and f(a)=b+a−2=3f(a)=b+a-2=3 gives b=5−a≥1b=5-a\ge1, so a∈{2,4}a\in\{2,4\}.

Step 3: two candidates.
- a=2a=2, b=3b=3: f(2k+1)=2k+2f(2k+1)=2k+2 and f(2k)=2k+1f(2k)=2k+1, i.e. f(n)=n+1f(n)=n+1.
- a=4a=4, b=1b=1: f(2k+1)=2k+4f(2k+1)=2k+4 and f(2k)=2k−1f(2k)=2k-1, i.e. f(n)=n+3f(n)=n+3 for odd nn and f(n)=n−1f(n)=n-1 for even nn.

Step 4: verification. For f(n)=n+1f(n)=n+1: f(f(n))=n+2f(f(n))=n+2. For the second function, if nn is odd then f(n)=n+3f(n)=n+3 is even, so f(f(n))=n+3−1=n+2f(f(n))=n+3-1=n+2; if nn is even then f(n)=n−1f(n)=n-1 is odd (and ≥1\ge1), so f(f(n))=n−1+3=n+2f(f(n))=n-1+3=n+2.

Answer. Exactly two functions: f(n)=n+1f(n)=n+1, and f(n)=n+3f(n)=n+3 for odd nn, f(n)=n−1f(n)=n-1 for even nn.

Lesson. Reduce f(f(n))=g(n)f(f(n))=g(n) to a recursion by applying ff again, then use the small values to pin down the free parameters, and always check whether more than one solution survives.