The biggest least common multiple

Source: Internet
Author: User

Title Link: http://acm.hust.edu.cn/vjudge/problem/visitOriginUrl.action?id=45783

Test instructions

Enter a number n, while A+b=n,[a,b] is represented as a-b least common multiple, and the largest number in all A, b least common multiple needs to be output.

Case:

Input

3

2

3

4

Output

1

2

3

Topic Analysis:

Two similar odd numbers must not have the number of conventions, so find the largest number of least common multiple, to find out the number of the One-second most recent number of the two no convention number.

When n is odd, two numbers are n/2,n/2+1;

When n is an even number, it is divided into two different situations:

When the N/2 is odd, two numbers are n/2+2,n/2-2;

When N/2 is an even number, two numbers are n/2+1,n/2-1;

However, it is also important to note that when n==2, using the above method to obtain negative numbers, so when n==2, output "1", when n!=2, then use the above method.

The source code is as follows:

1#include <iostream>2 using namespacestd;3 intMain ()4 {5     intT;6Cin>>T;7      for(intI=0; i<t;i++)8     {9         Long LongN; n must be a long long typeTenCin>>N; One         if(n==2) cout<<"1"<<Endl; A         Else if(n%2==0) -         { -             if(n/2%2==0) thecout<< (n/2-1) * (n/2+1) <<Endl; -             Else -cout<< (n/2+2) * (n/2-2) <<Endl; -         } +         Else -cout<<n/2* (n/2+1) <<Endl; +     } A     return 0; at}

The biggest least 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.