Input
An integer t, 1<=t<=100, denoting the number of testcases, followed by t lines, each containing a single integer n, 1<=n<=100.
Output
For each integer n given at input, display a line with the value of n!
Example
Sample input:
4
1
2
5
3
Sample output:
1
2
120
6
https://www.spoj.pl/problems/FCTRL2/
import java.io.BufferedReader; import java.io.InputStreamReader; import java.math.BigInteger; public class SmallFactorial { public static void main( String[] args ) throws Exception { BufferedReader br = new BufferedReader( new InputStreamReader( System.in ) ); BigInteger fact[] = new BigInteger[ 101 ]; fact[ 0 ] = BigInteger.ONE; fact[ 1 ] = BigInteger.ONE; fact[ 2 ] = new BigInteger( "2" ); fact[ 3 ] = new BigInteger( "6" ); int ind = 3; int numCasos = Integer.parseInt( br.readLine() ); int num; for( int i = 0; i < numCasos; i ++ ) { num = Integer.parseInt( br.readLine() ); while( num > ind ) { fact[ ind + 1 ] = fact[ ind ].multiply( BigInteger.valueOf( ind + 1 ) ); ind = ind + 1; } System.out.println( fact[ num ].toString() ); } } }
#include
ResponderEliminar#define tope 101
int main(){
int T,n; double fact[tope];
scanf("%d",&T);
// Precalcular
fact[0] = 1;
for (int p = 1; p < tope; p++)
fact[p] = p * fact[p - 1];
// Precalcular
for(int i=0; i<T; i++){
scanf("%d",&n);
printf("%.0f\n",fact[n]);
}
return 0;
}
"wrong answer"
ResponderEliminarhelp please
DAlvarado_UCLA@hotmail.com