BigInteger

Lab Java Intermediate 20 points

Read n (≤ 100) and print n! exactly using BigInteger, then the number of digits and the digit sum.

Input

One integer.

Output

Three lines.

Example

Input

25

Output

15511210043330985984000000
26
72
Sample input available Sample output available
Editor
Java

Hints

BigInteger is immutable - multiply returns a new value.

Solution explanation

BigInteger and BigDecimal handle numbers beyond long and exact decimals.

Show solution
import java.math.BigInteger;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        BigInteger f = BigInteger.ONE;
        for (int i = 2; i <= n; i++) {
            f = f.multiply(BigInteger.valueOf(i));
        }
        String digits = f.toString();
        int sum = 0;
        for (char c : digits.toCharArray()) {
            sum += c - '0';
        }
        System.out.println(digits);
        System.out.println(digits.length());
        System.out.println(sum);
    }
}
Output
Answer
HOME LEARN COMMUNITY DASHBOARD