Problem description
A positive integer n is known, asking for three numbers from 1~n, and the maximum number of least common multiple they can have.
Input format
Enter a positive integer n.
Output format output An integer that represents the least common multiple you found. Sample input 9 Sample output 504 data size and conventions
1 <= N <= 106.
Problem Solving Report:
The meaning of this question is that we need to find three numbers within the range of the 1~n, so that their least common multiple in this range is the largest. So, what was your first impression? My first impression is to find the number of three 22 coprime, so that only need to multiply, there is no need to numerator place.
Next, let's say one conclusion: two contiguous natural numbers greater than 1 are bound to coprime.
and for the 1~n range, it must be N (n-1) * (n-2) The product of the largest, if the three number is 22 coprime that is the best.
If n is an odd number, then N, n-1, n-2 must be 22 coprime, if there is some entanglement, then we analyze under what circumstances there may be a public factor. n is an odd number, then the n,n-1,n-2 must be two odd plus one even case. Male factor 2 Direct pass because there is only one even number. Assuming that one of the remaining n,n-2 is divisible by 3, then the number of common factors must be n or n-2 plus minus 3 to obtain the condition. For this reason, the product of n,n-1,n-2 is not only the largest, but also a certain 22 coprime.
If n is an even number, continue to analyze N (n-1) * (n-2), so that N and N-2 must have a common factor of 2, then change to the N (n-1) * (n-3). And then think about it, no ah, if the even number itself can be divisible by 3, then the formula N (n-1) * (n-3) is not set up, and the n-3 has a common factor of 3, and then think about it, the formula becomes (n-1) * (n-2) * (n-3), two odd clip a even situation.
1#include <iostream>2 using namespacestd; 3 4 intMain () {5 Long LongN, ans; 6 while(Cin >>N) {7 if(N <=2) { 8Ans =N; 9 } Ten Else if(n%2) { OneAns = n * (n-1) * (N-2); A } - Else { - if(n%3) ans = n * (n1) * (n3); the ElseAns= (n1) * (n2) * (n3); - } -cout << ans <<Endl; - } +Retur
Blue Bridge Cup algorithm training Max least common multiple