1. 


/**
* Angewandte Mathematik, SS09, IFB 2C
* ACM Problem #10323 (Factorial! You Must be Kidding!!!)
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=15&page=show_problem&problem=1264
*
* @author Christian Posselt
* @author Jonathan Schubert
* @version 1.0, 05/21/2009
*
* Status : Accepted
* Runtime: 0.268
*
* hint
* -----
* In order to solve this problem, consider the following post
* of the author in the board regarding negative input:
*
* "well... i guess the answers are quite obvious for positive input...
* well... when input is -1, f(-1) = f(0) / 0 = 1 / 0 = positive infinity
* (overflow)... den when u divide that by a negative num...
* u get another answer... and when u divide that by another negative
* num... what do you get?... that's the general idea...
* don't wanna give away too much"
*
*/

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

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));
Integer num;
String factorial;

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

if(line == null)
break;

if(line.isEmpty())
continue;

num = Integer.parseInt(line);

//depended output
switch(num)
{
case 8: {factorial = "40320";break;}
case 9: {factorial = "362880";break;}
case 10: {factorial = "3628800";break;}
case 11: {factorial = "39916800";break;}
case 12: {factorial = "479001600";break;}
case 13: {factorial = "6227020800";break;}
default:
{
if(num>13)
factorial = "Overflow!";
else if(num>=0)
factorial = "Underflow!";
else if(num<0 && num%2==0)
factorial = "Underflow!";
else
factorial = "Overflow!";
}
}

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

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


2.

/**
* 10323 - Factorial! You Must be Kidding!!!
*
* Studiengruppe: IFB2C
*
* Robert Reichart
* Elvin Uzeirovic
* Martin Pesl
*
* Run Time Submission Date
* 1.008 2009-05-31 11:55:08
*/

import java.util.Scanner;


public class Main {

/**
* @param args
*/
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int value = 0;
long[] vals = new long[14];
long tmp = 1;
vals[0] = 0;
for(int i = 1; i < 14;i++) {
tmp = tmp * i;
vals[i] = tmp;
}
while(sc.hasNext()) {
value = sc.nextInt();
if(value > 13) {
System.out.println("Overflow!");
}
else if(value < 8 && value >= 0) {
System.out.println("Underflow!");
}
else if(Math.abs(value) % 2 == 1 && value < 0) {
System.out.println("Overflow!");
}
else if(Math.abs(value) % 2 == 0 && value < 0) {
System.out.println("Underflow!");
}
else {
System.out.println(vals[Math.abs(value)]);
}
}
}

}