LCM Challenge(CF-236C)

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 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.

Examples

Input

9

Output

504

Input

7

Output
210

Note

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,要求找三个不大于 n 的数,使得他们的最小公倍数最大

思路:

要找三个数的最小公倍数需要从后向前找

由于两个相邻奇数的最小公倍数是他们的乘积,且 奇数*奇数=偶数,因此,两个相邻奇数与他们中间的那个偶数相乘后,就是这三个数的最小公倍数,故当 n 为奇数时,最大的最小公倍数是 n*(n-1)*(n-2)

当 n 偶数时,由于 n 与 n-2 此时均为偶数,因此最大的最小公倍数不再是 n*(n-1)*(n-2),延续 n 是奇数的作法,最大的最小公倍数为 n*(n-1)*(n-3),但此时不一定是最大的,由于 n 与 n-3 之间差 3,因此 n 与 n-3 的最小公倍数是要小于两数相乘的,此时就不能用第一个偶数与前两个奇数相乘,而是要用第二个偶数与前两个奇数相乘,即 (n-1)*(n-2)*(n-3)

Source Program

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9+7;
const int N = 500000+5;
const int dx[] = {-1,1,0,0,-1,-1,1,1};
const int dy[] = {0,0,-1,1,-1,1,-1,1};
using namespace std;
int main(){
    LL n;
    scanf("%lld",&n);
    if(n==1)
        printf("1\n");
    else if(n==2)
        printf("2\n");
    else{
        if(n%2)
            printf("%lld\n",n*(n-1)*(n-2));
        else{
            if(n%3)
                printf("%lld\n",n*(n-1)*(n-3));
            else
                printf("%lld\n",(n-1)*(n-2)*(n-3));
        }
    }
    return 0;
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值