#P1072. Inverse GCD and LCM Problem

    ID: 12752 Type: Default 1000ms 256MiB

Inverse GCD and LCM Problem

Inverse GCD and LCM Problem

Dr. Hanks is a renowned expert in the biotech field. His son, Hankson, after school, ponders an interesting "inverse problem" related to greatest common divisors (GCD) and least common multiples (LCM). In class, the teacher explained how to compute the GCD of two positive integers \(c_1\) and \(c_2\) and the LCM of the same two numbers. Now, Hankson considers the following inverse problem: Given four positive integers \(a_0, a_1, b_0, b_1\), find the number of positive integers \(x\) that satisfy both conditions:

  1. \(\gcd(x, a_0) = a_1\).
  2. \(\operatorname{lcm}(x, b_0) = b_1\).

Note that it is possible that no such \(x\) exists, or there might be several solutions. Your task is to count the number of \(x\) that meet the above two conditions.

Important: It is guaranteed that any formulas in the problem statement use \(\LaTeX\) for formatting.

inputFormat

The input consists of a single line with four space-separated positive integers: \(a_0\), \(a_1\), \(b_0\), \(b_1\).

Note: It is expected that \(a_1\) divides \(a_0\) and \(b_0\) divides \(b_1\). If these conditions are not met, then no solution exists.

outputFormat

Output a single integer indicating the number of positive integers \(x\) that satisfy both conditions.

sample

2 1 3 6
0