LCM ChallengeTime Limit:2000/1000ms (java/others) Memory Limit: 128000/64000kb (java/others) Submit Statusproblem 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 has to be distinct) which a re not greater than N. Can you help me to find the maximum possible least common multiple of these three integers?
Inputthe first line contains a integer n (1≤n≤10^6)-the N mentioned in the statement. Outputprint a single integer-the maximum possible LCM of three not necessarily distinct positive integers that is not g Reater than N.sample Input
9
Sample Output
504
Test instructions: Give a number n, ask for 3 less than equals n number, 3 number of least common multiple LCM (A1,A2,A3) the largest.
Analysis: Actually is to find 3 22 coprime number, but just how to find the problem.
According to the continuous two odd coprime, two natural numbers are contiguous coprime. So the answer is clear, the number of the 3 largest coprime is certainly the most least common multiple.
If n is odd, then the answer is N (n-1) * (n-2).
If n is an even number, or if N and n-2 coprime, then the answer is N (n-1) * (n-2), because they are the largest 3 coprime. But if N and n-2 are not coprime, then the answer is (n-3) * (n-1) * (n-2), because N-1 is definitely an odd number, with an odd number of methods.
1 /*2 * This code was made by xcw07543 * problem:10774 * verdict:accepted5 * Submission date:2015-07-16 10:24:026 * time:0ms7 * MEMORY:1672KB8 */9#include <bits/stdc++.h>Ten #defineLL Long Long One #definePII pair<int,int> A #defineINF 0x7f7f7f7f - using namespacestd; - Const intn=200000+ -; the -LL Cal (ll N)//even - { -LL ans=0; + //N n-1 n-3 - if(__GCD (n3)==1) Ans=max (ans, N (n1) * (n3)); + A //n-1 n-2 n-3 atAns=max (ans, (n1) * (n2) * (n3)); - - returnans; - } - - in intMain () - { to //freopen ("Input.txt", "R", stdin); + LL N; -scanf"%lld",&n); the if(n==1) printf ("1\n"); * Else if(n==2) printf ("2\n"); $ Else if(n==3) printf ("6\n");Panax Notoginseng Else if(n==4) printf ("12\n"); - Else if(n==5) printf ("60\n"); the Else + { A if((n&1)==0) cout<<cal (n) <<Endl; the Elsecout<<n* (n1) * (n2) <<Endl; + } - return 0; $}AC Code
Acdream LCM Challenge (least common multiple)