#P0287. Permutation Warm-Up

    传统题 1000ms 256MiB 显示标签>Codeforces

Permutation Warm-Up

题目描述

For a permutation p p of length n n ^{\text{∗}} , we define the function:

f(p)=i=1npiif(p) = \sum_{i=1}^{n} \lvert p_i - i \rvert

You are given a number n n . You need to compute how many distinct values the function f(p) f(p) can take when considering all possible permutations of the numbers from 1 1 to n n .

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

输入格式

Each test contains multiple test cases. The first line contains the number of test cases t t (1t100 1 \le t \le 100 ). The description of the test cases follows.

The first line of each test case contains an integer n n (1n500 1 \leq n \leq 500 ) — the number of numbers in the permutations.

输出格式

For each test case, output a single integer — the number of distinct values of the function f(p) f(p) for the given length of permutations.

输入输出样例 #1

输入 #1

5
2
3
8
15
43

输出 #1

2
3
17
57
463

说明/提示

Consider the first two examples of the input.

For n=2 n = 2 , there are only 2 2 permutations — [1,2] [1, 2] and [2,1] [2, 1] . $ f([1, 2]) = \lvert 1 - 1 \rvert + \lvert 2 - 2 \rvert = 0 $, $ f([2, 1]) = \lvert 2 - 1 \rvert + \lvert 1 - 2 \rvert = 1 + 1 = 2 $. Thus, the function takes 2 2 distinct values.

For n=3 n=3 , there are already 6 6 permutations: [1,2,3] [1, 2, 3] , [1,3,2] [1, 3, 2] , [2,1,3] [2, 1, 3] , [2,3,1] [2, 3, 1] , [3,1,2] [3, 1, 2] , [3,2,1] [3, 2, 1] , the function values of which will be 0,2,2,4,4 0, 2, 2, 4, 4 , and 4 4 respectively, meaning there are a total of 3 3 values.