CodeForces - 235A LCM Challenge

题目描述:

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.

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.

题目大意:

从1到n中挑选3个数(可重复),求挑选的三个数的最小公倍数最大可以是多少?

解题报告:

1:当n <= 2时,直接输出。有两条性质:相邻的两个奇数互质,相邻的两个正整数互质。

2:当n为奇数时:gcd(n, n-1) = 1, gcd(n, n-2) = 1, gcd(n-1, n-2) = 1可由上面两条性质得到。

3:当n为偶数时:理论上n*(n-1)*(n-2)最大,但有公约数,最少都要除2。考虑n-3,举例发现当n不为3的倍数时,n*(n-1)*(n-3)最大。n为3的倍数:比如6, 12。此时应该由(n-1)*(n-2)*(n-3)得到。最严谨的是列出表达式,作单调性分析,也可以得到答案。这里就不赘述了。

代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll n;
    scanf("%lld", &n);
    if(n <= 2)printf("%lld\n", n);
    else if(n & 1)printf("%lld\n", n*(n-1)*(n-2));
    else if(n % 3 != 0)printf("%lld\n", n*(n-1)*(n-3));
    else printf("%lld\n", (n-1)*(n-2)*(n-3));
    return 0;
}
发布了164 篇原创文章 · 获赞 4 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/jun_____/article/details/104091091
lcm
今日推荐