Codeforces Round #146 (Div. 1) A. LCM Challenge 水题

时间:2023-11-23 21:15:26

A. LCM Challenge

题目连接:

http://www.codeforces.com/contest/235/problem/A

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

Sample Output

504

Hint

题意

从1到n中选3个数,然后要求使得这三个数的lcm最大,问你这个lcm是多少

题解:

大胆猜想,不用证明

这三个数显然离n的距离不是很大,因为显然在某个区间内,存在三个互质的数,这三个数乘起来就好了

所以我们随便设一个下界然后跑就好了

代码

#include<bits/stdc++.h>
using namespace std; long long gcd(long long a,long long b)
{
if(b==0)return a;
return gcd(b,a%b);
}
int k = 100;
long long solve(long long a,long long b,long long c)
{
long long tmp = a*b/gcd(a,b);
tmp = tmp*c/gcd(tmp,c);
return tmp;
}
int main()
{
long long ans = 0;
int n;
scanf("%d",&n);
for(int i=n;i>=n-k&&i>=1;i--)
for(int j=n;j>=n-k&&j>=1;j--)
for(int t=n;t>=n-k&&t>=1;t--)
ans=max(ans,solve(i,j,t));
cout<<ans<<endl;
}