This page is still under construction.

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

Fact

Interview

Time limit1sMemory limit128 MB

Summary
For each N up to 10000, find the last non-zero digit of N! and print it with N right-aligned in a field of width 5.
Level

Medium5 of 10

Topics
Math, Number theory, Implementation, Simulation
Solved
No attempts yet

Problem

N!N! (read "NN factorial") is the product of the first NN positive integers, where NN is a non-negative integer. For example:

 N       N!
 0       1
 1       1
 2       2
 3       6
 4      24
 5     120
10 3628800

By convention 0!=10! = 1. Given an integer NN, write a program that finds the last non-zero digit of N!N! (the first non-zero digit counting from the right). For example, 5!=1205! = 120, so the last non-zero digit is 22.

Input

The input consists of several lines. Each line contains one non-negative integer NN with 0≤N≤100000 \le N \le 10000. The input continues until the end of file (EOF).

Output

For each NN, print one line. First print NN right-aligned in a field of width 55, then print " -> " (space, arrow, space), and finally print the last non-zero digit of N!N!. In other words, each line has the format %5d -> %d.

Examples1

  1. Example 1

    Input
    1
    2
    26
    125
    3125
    9999
    
    Expected output
        1 -> 1
        2 -> 2
       26 -> 4
      125 -> 8
     3125 -> 2
     9999 -> 8