Solution 1
Just to visualize solution 1. If we list all possible (x,f(x)), from 1,2,3,4,5 to 1,2,3,4,5 in a specific order, we get 5⋅5=25 different (x,f(x)) 's. Namely:
(1,1)(1,2)(1,3)(1,4)(1,5)
(2,1)(2,2)(2,3)(2,4)(2,5)
(3,1)(3,2)(3,3)(3,4)(3,5)
(4,1)(4,2)(4,3)(4,4)(4,5)
(5,1)(5,2)(5,3)(5,4)(5,5)
To list them in this specific order makes it a lot easier to solve this problem. We notice, In order to solve this problem at least one pair of (x,x) where x∈1,2,3,4,5 must exist.In this case I rather "go backwards". First fixing 5 pairs (x,x), (the diagonal of our table) and map them to the other fitting pairs (x,f(x)). You can do this in 5!5!=1 way. Then fixing 4 pairs (x,x) (The diagonal minus 1) and map them to the other fitting pairs (x,f(x)). You can do this in 4⋅4!5!=20 ways. Then fixing 3 pairs (x,x) (The diagonal minus 2) and map them to the other fitting pairs (x,f(x)). You can do this in 3!2!(5⋅4⋅3⋅6⋅3)+3!(5⋅4⋅3⋅6⋅1)=150 ways. Fixing 2 pairs (x,x) (the diagonal minus 3) and map them to the other fitting pairs (x,f(x)). You can do this in 2!3!(5⋅4⋅6⋅4⋅2)+2!2!(5⋅4⋅6⋅4⋅2)+2!2!(5⋅4⋅6⋅2⋅1)=380 ways. Lastly, fixing 1 pair (x,x) (the diagonal minus 4) and map them to the other fitting pairs (x,f(x)). You can do this in 4!5!+4⋅3!5!+5!=205 ways.
So 1+20+150+380+205=756
Solution 2
We perform casework on the number of fixed points (the number of points where f(x)=x). There must be at least one fixed point, given f(f(x)) has some value and is a fixed point. To better visualize this, use the grid from Solution 1.
Case 1: 5 fixed points
- Obviously, there must be 1 way to do so.
Case 2: 4 fixed points
- (45) ways to choose the 4 fixed points. For the sake of conversation, let them be (1,1),(2,2),(3,3),(4,4).
- The last point must be (5,1),(5,2),(5,3), or (5,4).
- There are (45)⋅4=20 solutions for this case.
Case 3: 3 fixed points
- (35) ways to choose the 3 fixed points. For the sake of conversation, let them be (1,1),(2,2),(3,3).
- Subcase 3.1: None of 4 or 5 map to each other
- The points must be (4,1),(4,2),(4,3) and (5,1),(5,2),(5,3), giving 3⋅3=9 solutions.
- Subcase 3.2: 4 maps to 5 or 5 maps to 4
- The points must be (4,5) and (5,1),(5,2),(5,3) or (5,4) and (4,1),(4,2),(4,3), giving 3+3=6 solutions.
- There are (35)⋅(9+6)=150 solutions for this case.
Case 4: 2 fixed points
- (25) ways to choose the 2 fixed points. For the sake of conversation, let them be (1,1),(2,2).
- Subcase 4.1: None of 3, 4, or 5 map to each other
- There are 2⋅2⋅2=8 solutions for this case, by similar logic to Subcase 3.1.
- Subcase 4.2: exactly one of 3,4,5 maps to another.
- Example: (3,4),(4,1),(5,2)
- (23)⋅2!=6 ways to choose the 2 which map to each other, and 2⋅2 ways to choose which ones of 1 and 2 they map to, giving 24 solutions for this case.
- Subcase 4.3: two of 3,4,5 map to the third
- Example: (3,5),(4,5),(5,2)
- (13) ways to choose which point is being mapped to, and 2 ways to choose which one of 1 and 2 it maps to, giving 6 solutions for this case.
- There are (25)⋅(8+24+6)=380 solutions.
Case 5: 1 fixed point
- (15) ways to choose the fixed point. For the sake of conversation, let it be (1,1).
- Subcase 5.1: None of 2,3,4,5 map to each other
- Obviously, there is 14=1 solution to this; all of them map to 1.
- Subcase 5.2: One maps to another, and the other two map to 1.
- Example: (2,3),(3,1),(4,1),(5,1)
- There are (24)⋅2! ways to choose which two map to each other, and since each must map to 1, this gives 12.
- Subcase 5.3: One maps to another, and of the other two, one maps to the other as well.
- Example: (2,3),(3,1),(5,4),(4,1)
- There are (24)⋅2!⋅2!/2! ways to choose which ones map to another. This also gives 12.
- Subcase 5.4: 2 map to a third, and the fourth maps to 1.
- Example: (4,2),(5,2),(2,1),(3,1)
- There are (24)⋅(12)=12 ways again.
- Subcase 5.5: 3 map to the fourth.
- Example: (2,4),(3,4),(5,4),(4,1)
- There are (14) ways to choose which one is being mapped to, giving 4 solutions.
- There are (15)⋅(1+12+12+12+4)=205 solutions.
Therefore, the answer is 1+20+150+380+205=756
~First
Solution 3
We can do some caseworks about the special points of functions f for x∈{1,2,3,4,5}. Let x, y and z be three different elements in set {1,2,3,4,5}. There must be elements such like k in set {1,2,3,4,5} satisfies f(k)=k, and we call the points such like (k,k) on functions f are "Good Points" (Actually its academic name is "fixed-points"). The only thing we need to consider is the "steps" to get "Good Points". Notice that the "steps" must less than 3 because the highest iterations of function f is 3. Now we can classify 3 cases of “Good points” of f.
Case 1: One "step" to "Good Points": Assume that f(x)=x, then we get f(f(x))=f(x)=x, and f(f(f(x)))=f(f(x))=f(x)=x, so f(f(f(x)))=f(f(x)).
Case 2: Two "steps" to "Good Points": Assume that f(x)=y and f(y)=y, then we get f(f(x))=f(y)=y, and f(f(f(x)))=f(f(y))=f(y)=y, so f(f(f(x)))=f(f(x)).
Case 3: Three "steps" to "Good Points": Assume that f(x)=y, f(y)=z and f(z)=z, then we get f(f(x))=f(y)=z, and f(f(f(x)))=f(f(y))=f(z)=z, so f(f(f(x)))=f(f(x)).
Divide set {1,2,3,4,5} into three parts which satisfy these three cases, respectively. Let the first part has a elements, the second part has b elements and the third part has c elements, it is easy to see that a+b+c=5. First, there are (a5) ways to select x for Case 1. Second, we have (b5−a) ways to select x for Case 2. After that we map all elements that satisfy Case 2 to Case 1, and the total number of ways of this operation is ab. Finally, we map all the elements that satisfy Case 3 to Case 2, and the total number of ways of this operation is bc. As a result, the number of such functions f can be represented in an algebraic expression contains a, b and c: (a5)⋅(b5−a)⋅ab⋅bc
Now it's time to consider about the different values of a, b and c and the total number of functions f satisfy these values of a, b and c:
For a=5, b=0 and c=0, the number of fs is (55)=1
For a=4, b=1 and c=0, the number of fs is (45)⋅(11)⋅41⋅10=20
For a=3, b=1 and c=1, the number of fs is (35)⋅(12)⋅31⋅11=60
For a=3, b=2 and c=0, the number of fs is (35)⋅(22)⋅32⋅20=90
For a=2, b=1 and c=2, the number of fs is (25)⋅(13)⋅21⋅12=60
For a=2, b=2 and c=1, the number of fs is (25)⋅(23)⋅22⋅21=240
For a=2, b=3 and c=0, the number of fs is (25)⋅(33)⋅23⋅30=80
For a=1, b=1 and c=3, the number of fs is (15)⋅(14)⋅11⋅13=20
For a=1, b=2 and c=2, the number of fs is (15)⋅(24)⋅12⋅22=120
For a=1, b=3 and c=1, the number of fs is (15)⋅(34)⋅13⋅31=60
For a=1, b=4 and c=0, the number of fs is (15)⋅(44)⋅14⋅40=5
Finally, we get the total number of function f, the number is 1+20+60+90+60+240+80+20+120+60+5=756
~Solution by BladeRunnerAUG (Frank FYC)
Note (fun fact)
This exact problem showed up earlier on the 2011 Stanford Math Tournament, Advanced Topics Test. This problem also showed up on the 2010 Mock AIME 2 here: https://artofproblemsolving.com/wiki/index.php/Mock_AIME_2_2010_Problems