問題一覧 > 通常問題

No.1663 Maximum Remainder

レベル : / AI推定難易度 : 133 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 341
作問者 : だれ / テスター : nok0
お気に入りにしたユーザー ProblemId : 6773 / 自分の提出
問題文最終更新日: 2026-04-28 14:42:02
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 312 (順位表) の他の問題:

Problem Statement

Find the maximum value of $(x+y)$ $\bmod$ $m$ over integers $x,$ $y$ satisfying $a\leq x\leq b$ and $c\leq y\leq d$.

Here, $A$ $\bmod$ $B$ denotes the remainder when $A$ is divided by $B$.

Input

$a$ $b$ $c$ $d$ $m$

  • All input values are integers.
  • $1\leq a\leq b\leq 1000$
  • $1\leq c\leq d\leq 1000$
  • $1\leq m\leq 1000$

Output

Print the answer on a single line.

Sample

Sample 1
Input
2 4 3 5 7
Output
6

For example, when $x=y=3$, $(x+y)$ $\bmod$ $m$ equals $6$, which is the maximum.

Sample 2
Input
1 1 5 6 9
Output
7

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