Solution to a problem [Luo Gu 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 and output formats

Input Format

This question multiple sets of data.

The first line of a positive integer \ (T \) , represents 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 Sample # 1

1
3

Sample Output # 1

6

Explanation

[Sample \ (1 \) Description]

Not more than \ (3 \) the maximum value of the least common multiple of two positive integers \ (\ mathrm LCM} {(2,3) =. 6 \) .

[Agreed] with the scale data

For \ (50 \% \) data, \ (. 1 \ Le T, n-\ Le 100 \) .

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

answer

A simple math problem.

Readily appreciate, \ (n-\) and \ (n-1 \) are relatively prime.

And the two prime numbers \ (\ mathrm {lcm} \ ) is the product of two numbers.

There are two points to note:

  1. Finally, the answer would exceed \ (int \) , need to open \ (Long \) \ (Long \) .
  2. Special attention sentence \ (n = 1 \) , the answer is \ (1 \) .

Code

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cctype>
#define int long long

using namespace std;

inline int gi()
{
    int f = 1, x = 0; char c = getchar();
    while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar();}
    while (c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar();}
    return f * x;
}

int t, n;

signed main()
{
    cin >> t;
    while (t--)
    {
        cin >> n;
        if (n == 1) cout << 1 << endl;//特判
        else cout << n * (n - 1) << endl;//输出两个数的乘积
    }
    return 0;
}

Guess you like

Origin www.cnblogs.com/xsl19/p/11114691.html