LCM Challenge(最小公倍数)

LCM Challenge
Crawling in process... Crawling failed Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u

Description

Some days ago, I learned the concept of LCM (least common multiple). I've played with it for several times and I want to make a big number with it.

But I also don't want to use many numbers, so I'll choose three positive integers (they don't have to be distinct) which are not greater than n. Can you help me to find the maximum possible least common multiple of these three integers?

Input

The first line contains an integer n (1 ≤ n ≤ 106) — the n mentioned in the statement.

Output

Print a single integer — the maximum possible LCM of three not necessarily distinct positive integers that are not greater than n.

Sample Input

Input
9
Output
504
Input
7
Output
210

Sample Output

Hint

The least common multiple of some positive integers is the least positive integer which is multiple for each of them.

The result may become very large, 32-bit integer won't be enough. So using 64-bit integers is recommended.

For the last example, we can chose numbers 7, 6, 5 and the LCM of them is 7·6·5 = 210. It is the maximum value we can get.


题意:给出n值,然后在1~~n中任意取三个数的最小公倍数,求所能得到的最大最小公倍数


题解:求三个数的最小公倍数,若n为奇数则n-1为偶数,n-2为奇数,最小公倍数为n(n-1)*(n-2)

      若n为偶数,则n-1为奇数,n-2为偶数,则n,n-1,n-2的最小公倍数为(n*(n-1)*(n-2))/2

      并非正确答案,三个数求最小公倍数先求两个数的最小公倍数,再用这个最小公倍数与第三个数求

      最小公倍数,若n为偶数则n-2也为偶数,所以n与n-2的最小公倍数(n*(n-2))/2,再与n-1求最小公倍数即为

      (n*(n-1)*(n-2))/2,由此可知此题中取小于n的三个数

      判断n是否为奇数,若为奇数则最大最小公倍数为n*(n-1)*(n-2)

      若为偶数,则为1.(n-1)*(n-2)*(n-3) 2.n若不能被3整除,则n*(n-1)*(n-3),因为若n能被三整除

      则n与n-3的公倍数(n*(n-3))/3

#include<stdio.h>   
 int main()  
 {  
     __int64 ans;  
     __int64 n;  
     __int64 temp;  
     while(scanf("%I64d",&n)!=EOF)  
     {if(n==1)  
     {  
         ans=1;  
     }  
     else if(n==2)  
     {  
         ans=2;  
     }  
     else if(n>2)  
     {  
   
         if(n%2==0)  
         {  
             ans=n*(n-1)*(n-2)/2;  
             temp=(n-1)*(n-2)*(n-3);  
             if(ans<temp) ans=temp;  
             if(n%3!=0)  
             {  
                 temp=n*(n-1)*(n-3);  
                 if(ans<temp) ans=temp;  
             }  
         }  
         else  
         {  
             ans=n*(n-1)*(n-2);  
         }  
     }  
     printf("%I64d\n",ans);}  
     return 0;  
 }  


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值