FACT1K - Editorial

PROBLEM LINK:

Contest

Author: thvardhan

Tester: thvardhan

DIFFICULTY:

Medium

PREREQUISITES:

Arbitrary-precision arithmetic,Factorial

PROBLEM:

You are given a number N you have to find its factorial.

QUICK EXPLANATION:

We use bigInteger instead of long/int in a loop which calculates factorial.

EXPLANATION:

We use a BigInteger class to solve this problem. BigIntegers can hold 10^200 digit long digits.
So here we make a object of BigInteger

BigInteger int=new BigInteger("1");

the 1 we passed in the constructor means the initial value of this big integer will be 1.Now we just take input from console from either scanner or bufferedreader as a string.And then we do this

   for (int i = 1; i <= n; i++) {
           int = fact.multiply(new BigInteger(i + ""));
       }

note we use strings not integers to store this big digit.this loop calculates the factorial and store it in int. now we just print it with

System.out.println(int);

AUTHOR’S SOLUTION:

author’s solution can be found here

//