Blue Bridge Cup practice system-algorithm training min Max common multiple

Source: Internet
Author: User

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.

Analysis:

The meaning of this question is to find three numbers within the range of the 1~n, so that their least common multiple in this range is the largest combination.

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.

Code

#include <iostream>using namespacestd; intMain () {Long LongN, ans;  while(Cin >>N) {if(N <=2) {ans=N; }           Else if(n%2) {ans= n * (n-1) * (N-2); }          Else {              if(n%3) ans = n * (n1) * (n3); ElseAns= (n1) * (n2) * (n3); } cout<< ans <<Endl; }      return 0; }   

Blue Bridge Cup practice system-algorithm training min Max common multiple

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.