#P7281. Divisibility of Consecutive Product Ranges
Divisibility of Consecutive Product Ranges
Divisibility of Consecutive Product Ranges
Given two sets of positive integers, the first set is \(\{a, a+1, \ldots, b\}\) and the second set is \(\{c, c+1, \ldots, d\}\). Determine whether the product of the second set, \(c\cdot(c+1)\cdots d\), is divisible by the product of the first set, \(a\cdot(a+1)\cdots b\).
Hint: The product of all integers from \(L\) to \(U\) can be represented as \(\frac{U!}{(L-1)!}\). To check divisibility, count the exponent of each prime \(p\) in both products. This can be done using the formula:
\(f(n,p)=\left\lfloor \frac{n}{p} \right\rfloor+\left\lfloor \frac{n}{p^2} \right\rfloor+\cdots\)
The exponent of \(p\) in the product \(\{L, L+1, \ldots, U\}\) is then \(f(U,p)-f(L-1,p)\). The divisibility condition holds if for every prime \(p\), we have
\(f(d,p)-f(c-1,p) \ge f(b,p)-f(a-1,p)\).
inputFormat
The input consists of four positive integers a
, b
, c
, and d
separated by spaces. Here:
- \(a\) and \(b\) define the first set \(\{a, a+1, \ldots, b\}\) (with \(a \le b\))
- \(c\) and \(d\) define the second set \(\{c, c+1, \ldots, d\}\) (with \(c \le d\))
outputFormat
Output a single line containing Yes
if the product \(c\cdot(c+1)\cdots d\) is divisible by the product \(a\cdot(a+1)\cdots b\); otherwise, output No
.
sample
2 4 1 4
Yes