If we were allowed to plug in a=0, we would find f(1)=1. With n=1, we then get f(f(m))=m, so f is bijective. Unfortunately, we are not allowed to plug in a=0, but it does put us on the right track.
We start by plugging in n=1. This gives us f(f(m)f(1))=m, which means that f is bijective. Indeed, if f(m)=f(n), then we directly get m=f(f(m)f(1))=f(f(n)f(1))=n and for every m there is an a such that f(a)=m, namely a=f(m)f(1). Now we plug in m=n, which gives us f(f(m)2)=m2=f(f(m2)f(1)). Due to the injectivity of f, it follows that f(m)2=f(m2)f(1). Choose now m1 such that f(m1)=1. (From our proof of surjectivity, we can choose m1=f(1)2, but that is not important.) If we plug in m=m1 in the above, we get 1=f(m12)f(1). In particular, f(1) is a divisor of 1, and since it must be a natural number, we conclude that f(1)=1.
If we now plug in n=1 again, we find that f(f(m))=m. Now we can plug in f(m) and f(n) for m and n so that we get the more classical equation
f(mn)=f(f(f(m))f(f(n)))=f(m)f(n)
This means that f is determined by the values f(p) with p prime.
Suppose we have an arbitrary prime number p, and let m and n be natural numbers such that f(p)=mn. It follows that f(m)f(n)=f(mn)=f(f(p))=p. Since f(m) and f(n) are natural numbers, it must be that f(m)=1 or f(n)=1. Due to injectivity, the only m for which f(m)=1 is the number m=1. Therefore, m=1 or n=1. We conclude that f(p) is a prime number.
Now suppose that p∤2024. In particular, this means that gcd(p,2024)=1, so p has a multiplicative inverse modulo 2024. Let b be a natural number in the residue class of the inverse, i.e., bp≡1mod2024. Since bp≥p>1, it follows from the second equation that f(bp)=bp, but also that f(bp+2024p)=bp+2024p. From the previous paragraph, however, it follows that f(bp)=f(b)f(p) and f((b+2024)p)=f(b+2024)f(p). This means that f(p) is a divisor of both bp and bp+2024p. Now we calculate that
gcd(bp,bp+2024p)=gcd(bp,2024p)=gcd(b,2024)p=p,
since b is the multiplicative inverse of p modulo 2024. Due to injectivity, we know that f(p)=1, so f(p)∣p implies that f(p)=p.
Suppose for a p∣2024 that f(p)=q, with q=p another prime number. Then it follows that f(q)=f(f(p))=p. So all prime numbers that do not map to themselves by f form pairs (p,q) with f(p)=q and f(q)=p. Since 2024=23⋅11⋅23, we have four solutions:
- f(p)=p for all prime numbers p. So f is the identity,
- f(2)=11,f(11)=2 and f(p)=p for all p∈/{2,11},
- f(2)=23,f(23)=2 and f(p)=p for all p∈/{2,23},
- f(11)=23,f(23)=11 and f(p)=p for all p∈/{11,23}.
It is easy to check that these functions also satisfy the conditions.