You will count the power of a prime in without computing , count the zeros at its end, and find the first factorial with a given number of zeros.
The idea. Add , , ... while the power of is at most . The zeros are the factors .
Your tasks.
legendre(n, p). Return the exponent of the prime p in n!.zeros(n). Return the number of zeros at the end of n!.first_with_zeros(z). Return the smallest n for which n! ends in exactly z zeros, or None if no factorial does. Search n from 0 to 5 * z + 5.Run your code once to unlock the worked solution.
Have you tried it?
Do the tasks in the editor first, and run the checker after each one. Its hints help when a check fails. When you are ready, compare your code with this solution.
Log in to join the discussion.
Loading…