HDU 4627 (Maximum Least public multiple), hdu4627

Source: Internet
Author: User

HDU 4627 (Maximum Least public multiple), hdu4627
HDU 4627Time Limit:1000 MSMemory Limit:32768KB64bit IO Format:% I64d & % I64u

Description

There are too unsolvable problem in the world. It cocould be about one or about zero. But this time it is about bigger number.
Given an integer n (2 <= n <= 10 9). We shoshould find a pair Positive integerA, B so that a + B = n and [a, B] is as large as possible. [a, B] denote the least common multiplier of a, B.

Input

The first line contains integer T (1 <= T <= 10000), denote the number of the test cases.
For each test cases, the first line contains an integer n.

Output

For each test cases, Print the maximum [a, B]In a line.

Sample Input

3234

Sample Output

123 in this case, because a number n is obtained from two positive integers a + B, you can first determine the range of a and B, it is from 1 to n/2. Because from n/2 + 1 to n, it is the same as the first half. No calculation is required. Then, the division of a and B is used, the maximum output value is LCM (a, B), that is, the least common multiple of a and B is the maximum. Note: This algorithm is easy to understand, but it is easy to time out. When you do it yourself, it is # include <stdio. h>
Int main ()
{
Int a, B, c;
Int max, min, t1, t2;
Int I, n, T;
Scanf ("% d", & T );
While (T --)
{
Scanf ("% d", & n );
Max = 0;
For (I = 1; I <= n/2; I ++)
{
A = I;
B = n-I;
A> B? T1 = a: t1 = B;
T2 = n-t1;
While (t2)
{
C = t1 % t2;
T1 = t2;
T2 = c;
}
Min = a * B/t1;
If (min> max)
Max = min;
}
Printf ("% d \ n", max );
}
Return 0;
}

 

In addition, this is a parity method, which is very simple and clever. It was learned by an ACM expert

# Include <stdio. h>

Int main ()
{
Int n, T;
Long max;
Scanf ("% d", & T );
While (T --)
{
Scanf ("% d", & n );
Max = 0;
If (n = 2) printf ("1 \ n ");
Else
{
If (n % 2 = 0)
{
Max = n/2;
If (max % 2 = 0) max = (max + 1) * (max-1 );
Else max = (max + 2) * (max-2 );
}
Else
{
Max = n/2;
Max = max * (max + 1 );
}
Printf ("% I64d \ n", max );
}
}
Return 0;
}

 

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.