GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Saturday, 13 August 2022

[Solution] Woeful Permutation Codeforces Solution



B. Woeful Permutation
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given a positive integer 𝑛

Find any permutation p of length n such that the sum lcm(1,p1)+lcm(2,p2)++lcm(n,pn) is as large as possible.

Here lcm(x,y) denotes the least common multiple (LCM) of integers x and y.

A permutation is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2,3,1,5,4] is a permutation, but [1,2,2] is not a permutation (2 appears twice in the array) and [1,3,4] is also not a permutation (n=3 but there is 4 in the array).

Input

Each test contains multiple test cases. The first line contains the number of test cases t (1t1000).

Solution Click Below:-  👉CLICK HERE👈
👇👇👇👇👇

 Description of the test cases follows.

The only line for each test case contains a single integer n (1n105).

It is guaranteed that the sum of n over all test cases does not exceed 105.

Output

For each test case print n integers p1p2pn — the permutation with the maximum possible value of lcm(1,p1)+lcm(2,p2)++lcm(n,pn).

If there are multiple answers, print any of them.


No comments:

Post a Comment