-
Notifications
You must be signed in to change notification settings - Fork 1
/
smallFactorials.java
56 lines (52 loc) · 1.71 KB
/
smallFactorials.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.BufferedInputStream;
import java.io.IOException;
class smallFactorials{
public static void main(String []args){
int a,b,rem,c;
final int LIMIT=1000;
long temp,carry;
String[]split_;
String str2="";
BufferedReader buffer=new BufferedReader(new InputStreamReader(System.in));
try{
String str=buffer.readLine();
a=Integer.parseInt(str);
while(a>0){
str=buffer.readLine();
b=Integer.parseInt(str);
carry=0;
str="";
str+=b;
while(--b>1){
str2="";
split_=str.split(" ");
c=split_.length;
// System.out.print(c+" ");
for(int i=--c;i>=0;i--){
temp=carry+Integer.parseInt(split_[i])*b;
str2=temp%LIMIT+" "+str2;
carry=temp/LIMIT;
// System.out.print(carry+" "+str2+" "+b+" "+ Long.parseLong(split_[i])+"\n");
}while(carry>0){
str2=carry%LIMIT+" "+str2;
carry/=LIMIT;
}
// System.out.println(str2);
str=str2;
}
str2=str.replace(' ','\0');
System.out.println(str2);
}
}catch(IOException e){
e.printStackTrace();
}finally {
try{
if(buffer!=null)buffer.close();
}catch(IOException ex){
ex.printStackTrace();
}
}
}
}