-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfact4.java
59 lines (55 loc) · 1.18 KB
/
fact4.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
57
58
59
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.StringTokenizer;
/*
ID: Xu Yan
LANG: JAVA
TASK: fact4
*/
/**
* Thoughts:
*
* Pitfalls:
*
* Take-away tips:
*
* @author Xu Yan
* @date July 14th, 2016
*/
public class fact4 {
public static void main(String[] args) throws IOException {
BufferedReader f = new BufferedReader(new FileReader("fact4.in"));
int N = Integer.parseInt(new StringTokenizer(f.readLine()).nextToken());
f.close();
int five_factor_count = 0;
for (int i = N; i >= 1; i--) {
int n = i;
while (5 * (n/5) == n) {
n /= 5;
five_factor_count++;
}
}
int answer = 1;
int twos = five_factor_count;
int fives = five_factor_count;
for (int i = N; i >= 1; i--) {
int n = i;
while (5 * (n/5) == n && fives > 0) {
n /= 5;
fives --;
}
while (2 * (n/2) == n && twos > 0) {
n /= 2;
twos --;
}
answer = (answer * n) % 10;
}
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("fact4.out")));
out.println(answer);
out.close();
}
}