The factorial operator means to multiply all the values counting down from a given number. For example, 5! is equal to 120:
5! -> 5 * 4 * 3 * 2 * 1 -> 120
Write a static method called factBack() that can undo a factorial. That is, it will return the original number that was "factorialed", or -1 if the number isn't a perfect factorial. You can do this by dividing by increasingly-larger numbers until only 1 is left:
120: 120/2 -> 60/3 -> 20/4 -> 5/5 -> 1
150: 150/2 -> 75/3 -> 25/4? -> -1
Preconditions:
Examples:
factBack(120) returns 5factBack(150) returns -1factBack(3628800) returns 10factBack(6) returns 3©2003–2016 Graham Mitchell
This assignment is licensed under a
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 United States License.
![]()