Description
Problem Description Given a positive integer N, Q ~ from any 1 N elect three numbers, their least common multiple can be up to much.
Input
Enter a positive integer N (1 <= N <= 10 ^ 6)
Output
Output An integer that represents you find the least common multiple of
Sample Input
9
Sample Output
504
ideas: the Internet, said the problem in a o (n ^ 3) will be T, are false! I o (log n) approach is also a T! inhuman. Later, the method can only be used mathematics.
If n is odd, the (maximum least common multiple) = n * (n-1 ) * (n-2)
if n is even and, if n is a multiple of 3, then the (maximum least common multiple) = (n-1) * (n-2) * (n -3)
or (greatest common divisor) = n * (n-1 ) * (n-3)
#include <cstdio> #include <iostream> #include <cmath> #include <string> #include <cstring> #include <algorithm> #include <queue> #include <vector> #include <map> using namespace std; #define ll long long const int inf = 0x3f3f3f3f; const int mod = 1e9+7; ll n, sum; int main() { scanf("%lld", &n); if(n <= 2)printf("%lld\n", n); else if(n%2 != 0) { sum = n*(n-1)*(n-2); printf("%lld\n", sum); } else if(n%3 == 0) { sum = (n-1)*(n-2)*(n-3); printf("%lld\n", sum); } else { sum = n*(n-1)*(n-3); printf("%lld\n", sum); } return 0; }