HUST_ACdream区域赛指导赛之手速赛系列(1)(2)F——GCD+1ll——LCM Challenge

时间:2021-12-08 05:18:04

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 ≤ 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
大意:输入一个人n,求不大于n的三个数的公共的最小公倍数,check小于等于3的情况,else 分成奇偶,因为奇数时,n和n-2都是奇数,肯定是互质的,如果是偶数的话那就是三种情况里面的最大值
HUST_ACdream区域赛指导赛之手速赛系列(1)(2)F——GCD+1ll——LCM ChallengeHUST_ACdream区域赛指导赛之手速赛系列(1)(2)F——GCD+1ll——LCM Challenge
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int GCD(long  a,long  b){
    return b == 0 ? a : GCD(b, a % b);
}
int main()
{
    int n;
    while(~scanf("%d",&n)){
    if(n == 1)
        printf("1\n");
    else if(n == 2)
        printf("2\n");
    else if(n == 3)
        printf("6\n");
    else {
        if((n % 2) == 1)
        printf("%lld\n",1ll*n*(n-1)*(n-2));
        else {
            long long max1 = 0;
            max1 = max(max1,1ll*(n-1)*(n-2)*(n-3));
            max1 = max(max1,1ll*n*(n-1)*(n-3)/GCD(n,n-3));
            max1 = max(max1,1ll*n*(n-1)*(n-2)/GCD(n,n-2));
            printf("%lld\n",max1);
            }
        }
    }
    return 0;
}
View Code

GCD写法:

int GCD(long  a,long  b){
    return b == 0 ? a : GCD(b, a % b);
}