Məsələlər
Jealous Numbers
Jealous Numbers
There is a trouble in Numberland, prime number \textbf{p} is jealous of another prime number \textbf{q}. She thinks that there are more integer numbers between \textbf{a} and \textbf{b}, inclusively, that are divisible by greater power of \textbf{q} than that of \textbf{p}. Help \textbf{p} to get rid of her feelings.
Let \textbf{α}(\textbf{n}, \textbf{x}) be maximal \textbf{k} such that \textbf{n} is divisible by \textbf{x^k}. Let us say that a number \textbf{n} is \textbf{p}-dominating over \textbf{q} if \textbf{α}(\textbf{n}, \textbf{p}) > \textbf{α}(\textbf{n}, \textbf{q}). Find out for how many numbers between \textbf{a} and \textbf{b}, inclusive are \textbf{p}-dominating over \textbf{q}.
\InputFile
The first line of the input file contains \textbf{a}, \textbf{b}, \textbf{p} and \textbf{q} (\textbf{1} ≤ \textbf{a} ≤ \textbf{b} ≤ \textbf{10^18}; \textbf{2} ≤ \textbf{p}, \textbf{q} ≤ \textbf{10^9}; \textbf{p} ≠ \textbf{q}; \textbf{p} and \textbf{q} are prime).
\OutputFile
Output one number - how many numbers \textbf{n} between \textbf{a} and \textbf{b}, inclusive, are \textbf{p}-dominating over \textbf{q}.
Giriş verilənləri #1
1 20 3 2
Çıxış verilənləri #1
4
Şərh: In the given example 3, 9, 15 and 18 are 3-dominating over 2.