There was a famous mathematician named Karl Friedrich Gauss. When he was young, he entered Gotinga University. One day, he met an old professor, and spoke to him. They chatted, and the professor asked Gauss about his age.
Gauss said: “The cube and the fourth power of my age contain each digit from 0 to 9 exactly once.”
The professor said: “Very good. It’s good coincidence because the square and the cube of my age contain each digit from 0 to 9 exactly once.”
How old was Gauss, and how old was the professor?

Answer
Their ages can’t end with 0, 1, 5 or 6, and must be either a multiple of 3 or a multiple of 9 minus 1 because the sum of its square and its cube or its cube and its fourth power is divisible by 9.
Gauss’s age is easy. Since 17^3=4913, 17^4=83521, 22^3=10648, 22^4=234256, Gauss’s age is between 18 and 21. The only possibility is 18. 18^3=5832, 18^4=104976.
The professor’s age is a little harder. It can be 47 to 99, and the possibilities are: 48, 53, 54, 57, 62, 63, 69, 72, 78, 84, 87, 89, 93, 98, 99. By trial and error, 69 satisfies this condition: 69^2=4761, 69^3=328509.
Therefore, Gauss was 18 and the professor was 69.