問題一覧 > 通常問題

No.3307 Almost Equal

レベル : / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 29
作問者 : sepa38 / テスター : dyktr_06 Nafmo2
お気に入りにしたユーザー ProblemId : 11913 / 自分の提出
問題文最終更新日: 2025-10-04 23:08:36
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. Show the original
yukicoder contest MMA Contest 020 (順位表) の他の問題:

Problem Statement

You are given positive integers $A, B, C, D$. Output the number of positive integers $i$ that satisfy the following condition.

  • $\displaystyle{\text{round} \left( i \times \frac{A}{B} \right) = \text{round} \left( i \times \frac{C}{D} \right)}$
Here, $\text{round} (x)$ denotes the value of $x$ rounded to the nearest integer, with fractions of one half or more rounded up. If there are infinitely many answers, output -1.

Constraints

  • All inputs are integers.
  • $1 \leq A < B \leq 10^9$
  • $1 \leq C < D \leq 10^9$

Input

$A \ B \ C \ D$

Output

Output the result in $1$ line.

Sample

Sample 1
Input
1 3 1 4
Output
7

For $i = {1, 2, 3, 4, 6, 7, 10}$, we have $\text{round} \left( \frac{i}{3} \right) = \text{round} \left( \frac{i}{4} \right)$.

Sample 2
Input
1 2 2 4
Output
-1

Sample 3
Input
216988846 221791262 433977693 443582525
Output
10243045170

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