forked from ngthanhtrung23/CompetitiveProgramming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathH.java
More file actions
31 lines (27 loc) · 802 Bytes
/
H.java
File metadata and controls
31 lines (27 loc) · 802 Bytes
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
import java.io.*;
import java.math.*;
import java.util.*;
public class H {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
PrintWriter pw = new PrintWriter(System.out);
int n = sc.nextInt();
BigInteger res = BigInteger.ZERO;
BigInteger N = BigInteger.valueOf(n);
BigInteger[] p = new BigInteger[5011];
p[0] = BigInteger.ONE;
for(int i = 1; i <= 5000; i++) {
p[i] = p[i-1].multiply(N);
}
BigInteger t = N.subtract(BigInteger.ONE).multiply(N.subtract(BigInteger.valueOf(2)));
t = t.multiply(p[n-3]);
for(int k = 3; k <= n; ++k) {
res = res.add(t.divide(BigInteger.valueOf(2)));
t = t.multiply(N.subtract(BigInteger.valueOf(k)));
t = t.divide(N);
}
pw.println(res);
pw.close();
sc.close();
}
}