I am working on designing an algorithm to find the largest factorial number present as a factor in some integer n. This problem is given in “How to solve it by computer” by R.G.Dormey.
could you help me in how to go about designing algorithm.. answer has to be a factor of the integer n and also a factorial number..
solution I thought of:
first confirm that integer is not prime. if prime, no further solution posible..
if not prime, find out the largest factor of the integer
check if it is a factorial number or not..
if yes, that is the answer
if not, find out second largest factor of the integer..
check if it is a factorial number or not…
and so on..
You’re looking to find the largest factorial that goes into your integer, so you just need to steadily increase your factors. I.e. Check to see if the resulting integer is divisible by 2, 3, 4, etc… The first time you get a failure you know that no larger factorial will divide your integer. E.g. if your integer is divisible by 2 … 6 but not 7, you know the answer is 6!.