You are not logged in. Please login at www.codechef.com to post your questions!

×

small factorial(shows runtime error! while runs fine in my machine)

import java.io.*;
import java.math.BigInteger;

public class small {
    public static final int MAX_SIZE = 100;

    public static BigInteger factorial( final int n ) {
        BigInteger result = BigInteger.ONE;
        if ( n == 0 ) {
            return BigInteger.ONE;
        } else {
            result = new BigInteger( "" + n ).multiply( factorial( n - 1 ) );
            return result;
        }
    }

    public static void main( final String[] args ) throws IOException {
        final BufferedReader br = new BufferedReader( new InputStreamReader( System.in ) );
        final int m = Integer.parseInt( br.readLine() );
        while ( m > 0 && m <= MAX_SIZE ) {

            final int n = Integer.parseInt( br.readLine() );
            if ( n <= MAX_SIZE ) {
                System.out.println( factorial( n ) );
            }
        }
    }
}

asked 22 Aug '12, 17:52

kiddo_koder's gravatar image

0★kiddo_koder
1111
accept rate: 0%

edited 22 Aug '12, 18:09

betlista's gravatar image

3★betlista ♦♦
16.9k49115225

Did you find the problem? I saw your AC submission.

(22 Aug '12, 18:12) betlista ♦♦3★
toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×175
×32

question asked: 22 Aug '12, 17:52

question was seen: 768 times

last updated: 22 Aug '12, 18:12