問題一覧 > 通常問題

No.3254 Xor, Max and Sum

レベル : / AI推定難易度 : 1925 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 68
作問者 : Iroha_3856 / テスター : lif4635 champignon tikuwa_
お気に入りにしたユーザー ProblemId : 12659 / 自分の提出
問題文最終更新日: 2025-09-05 04:13:46
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 481 菁々祭プログラミングコンテスト2025 (順位表) の他の問題:

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もしくは右上の雲マークをクリックしてアカウントを作成してください。