問題一覧 > 通常問題

No.821 Making Integers

レベル : / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 223
作問者 : Pulmn / テスター : ixmel
お気に入りにしたユーザー ProblemId : 2901 / 自分の提出
問題文最終更新日: 2019-04-26 21:14:16
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 212 (順位表) の他の問題:

Problem Statement

You are given positive integers $N,K$. Find the number of distinct possible values of the sum of the sequence $A$ after performing the following operation between $0$ and $K$ times, inclusive, on the sequence $A=(1,2,\dots ,N)$ of length $N$.

Operation: Choose an integer $i$ satisfying $1\le i\le N$, and multiply the value of $A_i$ by $-1$.

Input

$N$ $K$

$1\le K\le N\le 10^9$

Output

Print the number of distinct possible values of the sum of the sequence $A$ after the operations. Print a newline at the end.

Sample

Sample 1
Input
3 2
Output
6

The possible sequences $A$ after the operations are $(1,2,3),(-1,2,3),(1,-2,3),(1,2,-3),(-1,-2,3),(-1,2,-3),(1,-2,-3)$. Their sums are $6,4,2,0,0,-2,-4$, respectively, so there are $6$ possible values for the sum of the sequence after the operations.

Sample 2
Input
987654321 123456789
Output
114311841799268404

The answer may not fit in a 32-bit integer type.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。