The factorial of a positive integer N is written N! and is defined as the product of every positive integer that is at most N. For example, 4!=4×3×2×1=24.
You are given a positive integer N. Write a program that finds the smallest k such that N=a1!+a2!+⋯+ak!. Each ai is a positive integer, and the same value may appear more than once.
For N=10 the answer is 3, because 10=3!+2!+2! writes N as a sum of three factorials. For N=25 the answer is 2, because 25=4!+1!.