Jealous Numbers
Time limit3sMemory limit256 MB
Count integers in a huge range [a, b] whose exponent of prime p in factorization exceeds that of prime q.
- Level
Medium6 of 10
- Topics
- Math, Number theory, Binary search
- Solved
- No attempts yet
Problem
In Numberland the prime envies the prime . To settle the rivalry we count how often "wins" over within a range.
For a positive integer and a prime , let be the largest integer such that divides ; equivalently, is the exponent of in the prime factorization of .
We say that is -dominating over when .
Given , , , and , count how many integers with are -dominating over .
Input
A single line with four integers , , , and (; ; ; both and are prime).
Output
Print one integer: the number of integers in that are -dominating over .
Hint
For the sample, the integers in that are -dominating over are , , , and .