No.3254 Xor, Max and Sum
タグ : / 解いたユーザー数 68
作問者 :
Iroha_3856
/ テスター :
champignon
Problem Statement
You are given positive integers $N, M$.
Among all sequences $A = (A_1, A_2, \ldots, A_N)$ satisfying all of the following conditions, find the maximum possible value of the sum $\displaystyle \sum_{k = 1}^N A_k$.
- $0 \leq A_i \leq M\ (1 \leq i \leq N)$
- $A_1 \oplus A_2 \oplus \ldots \oplus A_N = 0$
Here, $\oplus$ denotes the bitwise exclusive OR.
Input
$N\ M$
All inputs satisfy the following constraints.
- $1 \leq N, M \leq 10^9$
- $N, M$ are integers
Output
Output the answer, followed by a newline.
Sample
Sample 1
Input
6 6
Output
36
When $A = (6, 6, 6, 6, 6, 6)$, the conditions are satisfied and the sum is $36$.
The sum cannot be $37$ or greater, so the maximum value is $36$.
Sample 2
Input
3 7
Output
14
When, for example, $A = (7, 7, 0)$, the conditions are satisfied and the sum is $14$.
The sum cannot be $15$ or greater, so the maximum value is $14$.
Sample 3
Input
5 100
Output
454
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。