[ACM]Q10212: The Last Non-zero Digit.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;
namespace Q10212
{
class Program
{
static private int[] iarr; static private char[] par = { ' ' }; static private BigInteger sum;
static void Main(string[] args)
{
for (; ; )
{
labelnm: Console.Write("n m>>>");
try
{
iarr = Array.ConvertAll<string, int>(Console.ReadLine().Split(par, StringSplitOptions.RemoveEmptyEntries), int.Parse);
if (iarr.Length != 2 || iarr[0] < iarr[1]) throw new Exception();
}
catch { goto labelnm; }
sum = 1;
for (int i = 0; i < iarr[1]; i++)
sum *= (iarr[0] - i);
for (int i = 0; i < sum.ToString().Length; i++)
{
if (sum.ToString().Substring(sum.ToString().Length - i - 1, 1) != "0")
{
Console.WriteLine("Ans={0}", sum.ToString().Substring(sum.ToString().Length - i - 1, 1));
break;
}
}
}
}
}
}