题库练习 Plus Minus Permutation
← 上一题 下一题 →

A16231 | Plus Minus Permutation

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

You are given $3$ integers — $n$ , $x$ , $y$ . Let's call the score of a permutation $^\dagger$ $p_1, \ldots, p_n$ the following value:

$$$$(p_{1 \cdot x} + p_{2 \cdot x} + \ldots + p_{\lfloor \frac{n}{x} \rfloor \cdot x}) - (p_{1 \cdot y} + p_{2 \cdot y} + \ldots + p_{\lfloor \frac{n}{y} \rfloor \cdot y}) $$ </span></p><p>In other words, the <span class="tex-font-style-it">score</span> of a permutation is the sum of $p\_i$ for all indices $i$ divisible by $x$ , minus the sum of $p\_i$ for all indices $i$ divisible by $y$ .</p><p>You need to find the maximum possible <span class="tex-font-style-it">score</span> among all permutations of length $n$ .</p><p>For example, if $n = 7$ , $x = 2$ , $y = 3$ , the maximum <span class="tex-font-style-it">score</span> is achieved by the permutation $\[2,\\color{red}{\\underline{\\color{black}{6}}},\\color{blue}{\\underline{\\color{black}{1}}},\\color{red}{\\underline{\\color{black}{7}}},5,\\color{blue}{\\underline{\\color{red}{\\underline{\\color{black}{4}}}}},3\]$ and is equal to $(6 + 7 + 4) - (1 + 4) = 17 - 5 = 12$ .</p><p> $^\\dagger$ A permutation of length $n$ is an array consisting of $n$ distinct integers from $1$ to $n$ in any order. For example, $\[2,3,1,5,4\]$ is a permutation, but $\[1,2,2\]$ is not a permutation (the number $2$ appears twice in the array) and $\[1,3,4\]$ is also not a permutation ( $n=3$ , but the array contains $4$$$).

输入格式

The first line of input contains an integer $t$ ( $1 \le t \le 10^4$ ) — the number of test cases.

Then follows the description of each test case.

The only line of each test case description contains $3$ integers $n$ , $x$ , $y$ ( $1 \le n \le 10^9$ , $1 \le x, y \le n$ ).

输出格式

For each test case, output a single integer — the maximum score among all permutations of length $n$ .

输入输出样例

输入 #1
8
7 2 3
12 6 3
9 1 9
2 2 2
100 20 50
24 4 6
1000000000 5575 25450
4 4 1
输出 #1
12
-3
44
0
393
87
179179179436104
-6
C++ 编辑器
输入
输出