import java.util.Scanner; public class Main { public void printResult(long n) { long result = 0; if(n <= 2) //此时最多只能选择两个数,不符合题意 return; if(n % 2 == 1) { result = n * (n - 1) * (n - 2); //奇数返回n,n-1,n-2 } else { if(n % 3 == 0) //说明n和n - 3有最大公约数3 result = (n - 1) * (n - 2) * (n - 3); //偶数12 的话 返回11,10,9 12,11,10的话会有公约数 else result = n * (n - 1) * (n - 3); //偶数返回n,n-1,n-3 } System.out.println(result); return; } public static void main(String[] args) { Main test = new Main(); Scanner in = new Scanner(System.in); long n = in.nextLong(); test.printResult(n); } }
原文地址:https://www.cnblogs.com/TengTengMa/p/8325461.html
时间: 2024-11-18 14:13:38