Luo Gu P5436 [XR-2] fate solution to a problem

P5436 [XR-2] fate

Topic background

Everything you exposure to weave the fate of large networks. Fate yet to come, though after Qianjie, but can not meet. Fate to in the grasslands can wait until a ship. - "a Zen monk."

Title Description

Zen want to know the fate of a size between him and his master. But how can we know it?

A Zen thought of a way, his first master agreement and a positive integer \ (n \) , then they each want no more than a heart \ (n \) positive integer.

A Zen believes that he and his master thought of these two numbers is the least common multiple greater, it means that the larger the fate between him and his master.

Master feels that this approach is appropriate, but he wants to know the maximum would be the least common multiple of the two numbers is.

Master of mathematics is not very good, so he asked a Zen. A Zen also think this question is very difficult, he wants you to tell him the answer.

Input Format

This question multiple sets of data.

The first line of a positive integer $ T, denotes the number of data sets.

The next \ (T \) lines, each a positive integer \ (n-\) , represents a positive integer and a master agreed Zen.

Output Format

For each set of data, a line a positive integer representing the answer.

Sample input and output

Input # 1

1
3

Output # 1

6

Description / Tips

Sample Description [1]

Does not exceed the maximum value of the least common multiple of 3 for two positive integers \ (\ mathrm LCM} {(2,3) =. 6 \) .

[Data] Scale and agreed
to \ (50 \% \) data, \ (. 1 \ Le T, n-\ Le 100 \) .

For \ (100 \% \) data, \ (. 1 \ Le T \ Le 100,. 1 \ n-Le \ Le ^ 10. 9 \) .

[Thinking]

Mathematical basis

A very interesting topic
to find the law + a little greedy thoughts
because of this need to find the least common multiple of two numbers within the maximum range
so it is easy to think of what violent tactics or
lcm (x, y) = xy / gcd (x, y)
, etc. the method
, however, when these methods are very easy to want to ignore the most easiest way
but it is a very excellent way
if you want to approach it in front of 100% of the data is difficult to had lost
but
can think about
because two mutual the least common multiple prime numbers are multiplying two numbers
so that will maximize the least common multiple
because if not relatively prime, then
after dividing gcd need to take up again
because after all, not the least of minutes can be about
so prime number is generally better than would be about the size of a pair of numbers is
therefore possible to select a prime number

While the adjacent two prime numbers must
therefore find two adjacent numbers of
the two adjacent numbers Mahayana the greater number out
so selecting n and n-1 output at this time it is optimal n * (n - 1) on the line
completely unnecessary so much trouble

Note To open long long! ! ! !

[Complete code]

#include<iostream>
#include<cstdio>

using namespace std;

int main()
{
    int T;
    cin >> T;
    long long n;
    for(int i = 1;i <= T;++ i)
    {
        cin >> n;
        if(n == 1)
            cout << 1 << endl;
        else
            cout << n * (n - 1) << endl;
    }
    return 0;
}

Guess you like

Origin www.cnblogs.com/acioi/p/11617063.html