蓝桥杯 算法训练 最大最小公倍数 JAVA

xiaoxiao2021-02-28  91

import java.math.BigInteger; import java.util.Scanner; class Main{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); long n = sc.nextLong(); BigInteger num = new BigInteger("1"); if(n<=2){ System.out.println(2); return; }else{ if(n%2 != 0){ BigInteger t1 = new BigInteger(n+""); BigInteger t2 = new BigInteger((n-1)+""); BigInteger t3 = new BigInteger((n-2)+""); num=num.multiply(t1).multiply(t2).multiply(t3); }else{ if(n%3 == 0){ BigInteger t1 = new BigInteger((n-3)+""); BigInteger t2 = new BigInteger((n-1)+""); BigInteger t3 = new BigInteger((n-2)+""); num=num.multiply(t1).multiply(t2).multiply(t3); }else{ BigInteger t1 = new BigInteger(n+""); BigInteger t2 = new BigInteger((n-1)+""); BigInteger t3 = new BigInteger((n-3)+""); num=num.multiply(t1).multiply(t2).multiply(t3); } } } System.out.println(num); } }
转载请注明原文地址: https://www.6miu.com/read-54510.html

最新回复(0)