Программа работает. Вылезает ошибка: "Программа работала слишком долго и была закрыта"
package com.javarush.task.task15.task1531;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigInteger;
/*
Факториал
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int input = Integer.parseInt(reader.readLine());
reader.close();
System.out.println(factorial(input));
}
public static String factorial(int n) {
BigInteger temp = new BigInteger("1");
BigInteger inp = new BigInteger(n+"");
while(true)
{
if(inp.compareTo(BigInteger.ZERO)==0)
return ""+1;
if(inp.compareTo(BigInteger.ONE)==0)
break;
temp = temp.multiply(inp);
inp = inp.subtract(BigInteger.ONE);
}
return ""+temp;
}
}