1. 

/**
* Angewandte Mathematik, SS09, IFB 2C
* ACM Problem #623 (500!)
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=8&page=show_problem&problem=564
*
* @author Christian Posselt
* @author Jonathan Schubert
* @version 1.0, 05/19/2009
*
* Status : Accepted
* Runtime: 1.624
*/

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;


class Main
{
public static void main(String[] args) throws IOException
{
//set up all variables needed
StringBuilder bu = new StringBuilder();
BufferedReader Reader = new BufferedReader(new InputStreamReader(System.in));
BigInteger num, factorial;

while(true)
{
//read-in
String line = Reader.readLine();

if(line == null || line.length()== 0)
break;

//calculate factorial
num = new BigInteger(line);
factorial = factorial(num);

//append
bu.append(num + "!\n" + factorial + "\n");
}

//print result
System.out.print(bu.toString());
}

/**
* factorial
*
* Calculates the factorial of an input number n
*
* @param n: BigInteger of the input number
* @return BigInteger, which is the factorial
*/
public static BigInteger factorial(BigInteger n)
{
BigInteger result = BigInteger.ONE;

for(BigInteger i= BigInteger.ONE;i.compareTo(n)<=0;i=i.add(BigInteger.ONE))
result = result.multiply(i);

return result;
}
}

2.

/**
* Angewandte Mathematik, SS09, IFB 2C
* ACM Problem #623 (500!)
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=8&page=show_problem&problem=564
*
* @author Christian Posselt
* @author Jonathan Schubert
* @version 1.1, 05/21/2009
*
* Status : Accepted
* Runtime: 1.004
*/

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.Map;
import java.util.TreeMap;


class Main
{
//Set of saved factorials
static Map<Integer, BigInteger> set = new TreeMap<Integer, BigInteger>();

public static void main(String[] args) throws IOException
{
//set up all variables needed
StringBuilder bu = new StringBuilder();
BufferedReader Reader = new BufferedReader(new InputStreamReader(System.in));
BigInteger num, factorial;

while(true)
{
//read-in
String line = Reader.readLine();

if(line == null || line.length()== 0)
break;

//calculate factorial
num = new BigInteger(line);
factorial = factorial(num);

//append
bu.append(num + "!\n" + factorial + "\n");
}

//print result
System.out.print(bu.toString());
}

/**
* factorial
*
* Calculates the factorial of an input number n
*
* @param n: BigInteger of the input number
* @return BigInteger, which is the factorial
*/
public static BigInteger factorial(BigInteger n)
{
BigInteger result = BigInteger.ONE;
int setsize = set.size();
boolean done = false;

//if n > largest key in Map, use factorial of largest entry to start with
if(n.intValue()>(set.size()) && !(set.isEmpty()))
{
result = set.get(setsize);
}

//if n <= largest key in Map, read the result
if(n.intValue()<=(set.size()) && !(set.isEmpty()))
{
//special case zero
if(n.compareTo(BigInteger.ZERO)==0)
return BigInteger.ONE;
result = set.get(n.intValue());
done = true;
}

//calculate necessary steps, save factorial into Map
for(int i= setsize+1;i<=n.intValue() && !done;i++)
{
result = result.multiply(new BigInteger(((Integer)i).toString()));

//saves <i, result>...e.g. 1->1; 6->24 etc...
set.put(i, result);
}

return result;
}
}