Three Digits
Time limit1sMemory limit256 MB
Given n up to 10^7, print the last three digits of n! after removing every trailing zero, keeping leading zeros.
- Level
Medium5 of 10
- Topics
- Number theory, Math
- Solved
- No attempts yet
Problem
Per is obsessed with factorials. He calculates them, estimates them, reads about them, draws them, and dreams about them. The value is tattooed on his back.
He noticed long ago that a factorial ends with several zeros, and he wrote a program that counts those trailing zeros. For example ends with 600, so it has 2 trailing zeros. Now he wants to look one step further, at the 3 digits that sit right before the trailing zeros. Removing the trailing zeros from leaves 4790016, whose last 3 digits are 016.
You are given an integer . Remove every trailing zero from and find the last 3 digits of what remains. If fewer than 3 digits remain, find all of them.
Input
The first line contains one integer ().
Output
Print, on one line, the last 3 digits of after every trailing zero is removed. Print a leading 0 as it is. If the remaining value is 4032, print 032. If the remaining value has fewer than 3 digits, print that value as it is.