This page is still under construction.

Parts of this page are still being built. What you see may change.

Three Digits

Time limit1sMemory limit256 MB

Summary
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 12!=47900160012! = 479001600 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 12!12! 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 12!12! leaves 4790016, whose last 3 digits are 016.

You are given an integer nn. Remove every trailing zero from n!n! 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 nn (1≤n≤1071 \le n \le 10^7).

Output

Print, on one line, the last 3 digits of n!n! 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.

Examples2

  1. Example 1

    Input
    5
    
    Expected output
    12
    
  2. Example 2

    Input
    12
    
    Expected output
    016