Gats and the Leftover Treaty
Gats supervises cats after a day of fishing. Cat caught fish.
For a chosen positive integer bowl capacity , each cat places their fish into as many full bowls of exactly fish as possible. Cat then has a leftover amount , defined as the unique integer satisfying
and
A capacity is called harmonious when both of the following conditions hold:
- All cats have the same leftover amount: .
Given an allowed interval , determine how many integer capacities in this interval are harmonious.
Input
The first line contains three integers , , and (, ), representing the number of cats and the allowed range of bowl capacities.
Output
Print one integer: the number of harmonious bowl capacities satisfying .
Samples
Sample 1
Input
3 2 20 11 23 35
Output
5
The harmonious capacities are , , , , and . For each of them, all three cats have the same leftover, and that leftover is relatively prime to the capacity.
Sample 2
Input
2 2 10 12 12
Output
2
Because both cats caught the same number of fish, their leftovers are equal for every capacity. Within the allowed range, only capacities and also satisfy the coprimality requirement.