码迷,mamicode.com
首页 > 其他好文 > 详细

acd LCM Challenge(求1~n的随意三个数的最大公倍数)

时间:2014-06-24 15:01:58      阅读:168      评论:0      收藏:0      [点我收藏+]

标签:des   style   class   blog   code   color   

Problem 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 thann. 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?≤?10^6) — 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

9

Sample Output

504
仅仅要这三个数中有两个数是奇数一个是偶数,最小公倍数就是这三个数的积。
#include<stdio.h>
int main()
{
    long long  LCM,n;
    while(scanf("%lld",&n)>0)
    {
        if(n==1)LCM=1;
        if(n==2)LCM=2;
        if(n>2)
        {
            if(n%2)LCM=n*(n-1)*(n-2);
            else
            {
                if(n*(n-1)*(n-2)/2<n*(n-1)*(n-3))
                    LCM=n*(n-1)*(n-3);
                else LCM=n*(n-1)*(n-2)/2;
            }
        }
        printf("%lld\n",LCM);
    }
}


acd LCM Challenge(求1~n的随意三个数的最大公倍数),布布扣,bubuko.com

acd LCM Challenge(求1~n的随意三个数的最大公倍数)

标签:des   style   class   blog   code   color   

原文地址:http://www.cnblogs.com/mengfanrong/p/3805798.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!