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.
Sample Input
9
504
7
210
Sample Output
Hint
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值,然后在1~~n中任意取三个数的最小公倍数,求所能得到的最大最小公倍数
题解:求三个数的最小公倍数,若n为奇数则n-1为偶数,n-2为奇数,最小公倍数为n(n-1)*(n-2)
若n为偶数,则n-1为奇数,n-2为偶数,则n,n-1,n-2的最小公倍数为(n*(n-1)*(n-2))/2
并非正确答案,三个数求最小公倍数先求两个数的最小公倍数,再用这个最小公倍数与第三个数求
最小公倍数,若n为偶数则n-2也为偶数,所以n与n-2的最小公倍数(n*(n-2))/2,再与n-1求最小公倍数即为
(n*(n-1)*(n-2))/2,由此可知此题中取小于n的三个数
判断n是否为奇数,若为奇数则最大最小公倍数为n*(n-1)*(n-2)
若为偶数,则为1.(n-1)*(n-2)*(n-3) 2.n若不能被3整除,则n*(n-1)*(n-3),因为若n能被三整除
则n与n-3的公倍数(n*(n-3))/3
#include<stdio.h>
int main()
{
__int64 ans;
__int64 n;
__int64 temp;
while(scanf("%I64d",&n)!=EOF)
{if(n==1)
{
ans=1;
}
else if(n==2)
{
ans=2;
}
else if(n>2)
{
if(n%2==0)
{
ans=n*(n-1)*(n-2)/2;
temp=(n-1)*(n-2)*(n-3);
if(ans<temp) ans=temp;
if(n%3!=0)
{
temp=n*(n-1)*(n-3);
if(ans<temp) ans=temp;
}
}
else
{
ans=n*(n-1)*(n-2);
}
}
printf("%I64d\n",ans);}
return 0;
}