C. LCM Challenge
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
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.
Examples
input
9
output
504
input
7
output
210
#include <bits/stdc++.h>
#define maxn 100005
#define MOD 1000000007
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b){
return b ? gcd(b, a % b) : a;
}
int main(){
ll n;
scanf("%I64d", &n);
if(n == 1)puts("1");
else if(n == 2)puts("2");
else{
if(n&1)
cout << n * (n - 1) * (n - 2) << endl;
else{
ll k1 = n * (n - 2) / gcd(n, n-2) * (n-1);
ll k2 = (n-1) * (n-2) * (n-3);
ll k3 = n * (n-3) / gcd(n, n-3) * (n-1);
cout << max(max(k1, k2), k3) << endl;
}
}
return 0;
}