一周半前开始帮老师写东西,到今早一点才完成,还只是初稿,拖欠不少作业,博客也鸽了,先补一篇。
import java.io.IOException;
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException{
Scanner sc=new Scanner(System.in);
String n=sc.next();
BigInteger a,b,c,d,e,f,g,h;
a=new BigInteger(n);
b=new BigInteger("1");
c=a.subtract(b);//n-1
d=c.subtract(b);//n-2
e=d.subtract(b);//n-3
f=e.multiply(d).multiply(c).multiply(b).multiply(a);//n(n-1)(n-2)(n-3)
g=new BigInteger("24");
h=f.divide(g);
System.out.println(h);
}
}
思路:两条对角线确定一个交点,四个顶点确定两条相交的对角线,所以就是无顺序的从顶点中取四个顶点,也就是组合数C下面写个n,上面写个4。
由于n<=10^5,因此需要BigInteger类。
BigInteger类:
注意输入时用string类接收。