Mars Car Numbers
InterviewTime limit1sMemory limit1024 MB
Given N, find the lexicographically largest permutation in the first half and the smallest in the second half of all permutations of 1 to N.
- Level
Medium5 of 10
- Topics
- Combinatorics, Implementation
- Solved
- No attempts yet
Statement
Mars is introducing a new car number system. In this system, each number plate is a permutation of , that is, a sequence in which each of the numbers appears exactly once.
For administrative purposes, Mars is divided into a southern and a northern hemisphere. So that a car's number shows which hemisphere it comes from, the southern hemisphere uses the lexicographically smallest plates, and the northern hemisphere uses the lexicographically largest plates.
The governors want special numbers. The southern governor takes the lexicographically largest number among the plates of the southern hemisphere, and the northern governor takes the lexicographically smallest number among the plates of the northern hemisphere.
Write a program that finds the numbers the two governors receive.
denotes the product . A sequence is lexicographically smaller than if, for some index , , , \ldots, and .
Input
The only line of the text file contains an integer (), the length of the Mars car numbers.
Output
The text file must contain exactly two lines, each with integers separated by spaces. The first line is the number of the southern governor's car, and the second line is the number of the northern governor's car.