Link:http://acdream.info/problem?pid=1077
LCM Challenge
Time Limit: 2000/1000MS (Java/Others)
Memory Limit: 128000/64000KB (Java/Others)
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 ≤ 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
AC code:
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
#define LL long long
#define MAXN 1000010
using namespace std;
int main()
{
LL ans,n;
while(cin>>n)
{
if(n<=2)
{
ans=n;
}
else if(n%2)
{
ans=n*(n-1)*(n-2);
}
else
{
if(n%3)
{
ans=n*(n-1)*(n-3);
}
else
{
ans=(n-1)*(n-2)*(n-3);
}
}
cout<<ans<<endl;
}
return 0;
}

本文介绍了一道编程挑战题目——给定一个整数n,找出不超过n的三个正整数(可以相同),使得它们的最小公倍数(LCM)最大,并提供了解决方案的代码实现。
1718

被折叠的 条评论
为什么被折叠?



