-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA_Permutation_Warm_Up.cpp
More file actions
193 lines (169 loc) · 3.63 KB
/
A_Permutation_Warm_Up.cpp
File metadata and controls
193 lines (169 loc) · 3.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#include <bits/stdc++.h>
#include <algorithm>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
#define nl '\n'
#define sp ' '
#define pi 2 * acos(0.0)
// Types of declarations /////////////////////////////////
#define ui unsigned int
#define us unsigned short
#define all(x) x.begin(), x.end()
#define ull unsigned long long
#define ll long long
#define ld long double
#define vstr vector<string>
#define vll vector<ll>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vii vector<pair<int, int>>
#define pii pair<int, int>
// Odd Even /////////////////////////////////////////////
bool odd(ll num) { return ((num & 1) == 1); }
bool even(ll num) { return ((num & 1) == 0); }
//////////////////////////////////////////////////////// Prime
bool isPrime(int n)
{
for (int i = 2; i * i <= n; i++)
{
if (n % i == 0)
return false;
}
return true;
}
///////////////////////////////////////////////////////// LCM GCD
long long gcd(long long a, long long b)
{
while (b != 0)
{
long long temp = b;
b = a % b;
a = temp;
}
return a;
}
long long lcm(long long a, long long b)
{
return (a / gcd(a, b)) * b;
}
////////////////////////////////////////////////////////// SQR ROOT
long long sqrt(long long x)
{
long long s = 0, e = 2e9, res = s;
while (s <= e)
{
long long m = (s + e) / 2;
if (m * m <= x)
res = m, s = m + 1;
else
e = m - 1;
}
return res;
}
/*
check all edge cases
check for integer overflow
check for corner cases
check for constraints
check for time complexity
check for array bounds
check for negative values
*/
/*
vi a(n);
for(int i=0; i<n; i++){
cin>>a[i];
}
*/
#define cno cout << "NO\n"
#define cyes cout << "YES\n"
/*----------------------------------------------------------------------------*/
void solve()
{
int n;
cin >> n;
int ans = (n * n) / 4 + 1;
cout << ans << nl;
}
/*
For a permutation p
of length n
∗
, we define the function:
f(p)=∑i=1n|pi−i|
You are given a number n
. You need to compute how many distinct values the function f(p)
can take when considering all possible permutations of the numbers from 1
to n
.
∗
A permutation of length n
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
(1≤t≤100
). The description of the test cases follows.
The first line of each test case contains an integer n
(1≤n≤500
) — the number of numbers in the permutations.
Output
For each test case, output a single integer — the number of distinct values of the function f(p)
for the given length of permutations.
Example
InputCopy
5
2
3
8
15
43
OutputCopy
2
3
17
57
463
Note
Consider the first two examples of the input.
For n=2
, there are only 2
permutations — [1,2]
and [2,1]
. f([1,2])=|1−1|+|2−2|=0
, f([2,1])=|2−1|+|1−2|=1+1=2
. Thus, the function takes 2
distinct values.
For n=3
, there are already 6
permutations: [1,2,3]
, [1,3,2]
, [2,1,3]
, [2,3,1]
, [3,1,2]
, [3,2,1]
, the function values of which will be 0,2,2,4,4
, and 4
respectively, meaning there are a total of 3
values.
*/
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int t = 1;
cin >> t;
while (t--)
solve();
}