問題一覧 > 教育的問題

No.2781 A%B Problem

レベル : / AI推定難易度 : 189 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 123
作問者 : 👑 p-adic / テスター : Taka
お気に入りにしたユーザー ProblemId : 9496 / 自分の提出
問題文最終更新日: 2023-09-25 10:29:39
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 433 (順位表) の他の問題:

Problem Statement

You are given $2$ integers $A, B$ as input, where $B \neq 0$.

 

Find the remainder when $A$ is divided by $B$.

 

In this problem, "the remainder when $A$ is divided by $B$" refers to the unique non-negative integer $r$ less than $|B|$ such that there exists an integer $q$ satisfying $A = Bq+r$.

Input

The input is given from standard input on $1$ line in the following format:

$A$ $B$

That is, $A, B$ are given separated by a half-width space.

Constraints

The input satisfies the following constraints:

  • $A$ is an integer satisfying $-10^2 \leq A \leq 10^2$.
  • $B$ is an integer satisfying $-10^2 \leq B \leq 10^2$ and $B \neq 0$.

Output

Output the remainder when $A$ is divided by $B$ on $1$ line.

Print a newline at the end.

Sample

Sample 1
Input
1 1
Output
0

Since $1 = 1 \times 1 + 0$ and $0 < |1|$, the remainder when $1$ is divided by $1$ is $0$.

Sample 2
Input
1 -2

Note that $B$ may be negative, as in this case.

Output
1

Since $1 = (-2) \times 0 + 1$ and $1 < |{-2}|$, the remainder when $1$ is divided by $-2$ is $1$.

Sample 3
Input
-1 2

Note that $A$ may be negative, as in this case.

Output
1

Since $-1 = 2 \times (-1) + 1$ and $1 < |2|$, the remainder when $-1$ is divided by $2$ is $1$.

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