欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF2108A.Permutation Warm-Up
Permutation Warm-Up
For a permutation of length , we define the function:
$$f(p) = um_{i=1}^{n} \lvert p_i - i \rvert$$</p><p>You are given a number$n$. You need to compute how many <span class="tex-font-style-bf">distinct</span> values the function$f(p)$can take when considering <span class="tex-font-style-bf">all possible</span> permutations of the numbers from$1$to$n$.</p><div class="statement-footnote"><p>$^{\text{∗}}$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 \le t \le 100$). The description of the test cases follows. The first line of each test case contains an integer $n$ ($1 \leq n \leq 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. ## 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]) = \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$ 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. ## Samples ```input1 5 2 3 8 15 43 ``` ```output1 2 3 17 57 463 ```$$在线编程 IDE
建议全屏模式获得最佳体验
键盘快捷键
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |
第 1 行,第 1 列
0 字符
-
最近自测结果
暂未运行
最近递交结果
暂无递交记录