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