Number Sets
Time limit2sMemory limit512 MB
Count the connected components formed when numbers A through B are merged whenever they share a prime factor at least P.
- Level
Medium7 of 10
- Topics
- Union-find, Number theory, Math
- Solved
- No attempts yet
Problem
The consecutive natural numbers from to are given. Alice wants to group them into sets.
The sets are built as follows.
- At the start, make one set of size 1 for each number.
- For every pair of numbers in the range, if and have a common prime factor that is at least , merge the set containing with the set containing .
For example, take , , . The sets are , , , , , , so the number of sets is 6.
Given , , and , find how many sets this procedure produces.
Input
The first line contains , , and separated by spaces. (, , )
Output
Print the number of sets produced by the rule above.