算法训练 最大最小公倍数

                                                                                算法训练 最大最小公倍数  

   

题描述

已知一个正整数N,问从1~N中任选出三个数,他们的最小公倍数最大可以为多少。

输入格式

输入一个正整数N。

输出格式
输出一个整数,表示你找到的最小公倍数。
样例输入
9
样例输出
504
数据规模与约定

1 <= N <= 106

import java.util.*;
public class  Main {
	public static void main(String[] args)
	{
		Scanner in=new Scanner(System.in);
		 long n=in.nextLong();
		 long s;
		 if(n<=2)
		 {
			 s=n;
		 }
		 else if(n%2==1)
		 {  
			 s=n*(n-1)*(n-2);
			 
		 }
		 else
		 {
			 if(n%3==0)  
			        s=(n-1)*(n-2)*(n-3);  
			        else  
			        s=n*(n-1)*(n-3);  
			    
		 }
		 
		 System.out.print(s);
		
	}

}



猜你喜欢

转载自blog.csdn.net/sinat_27406925/article/details/51132201