Number Sets (Large)
Time limit50sMemory limit512 MB
Given an interval of consecutive integers and a threshold P, merge pairs sharing a prime factor of at least P, then count the remaining sets.
- Level
Medium6 of 10
- Topics
- Union-find, Number theory, Math, Prefix sum
- Solved
- No attempts yet
Problem
You are given an interval of consecutive integers and an integer . At the start, every integer in the interval sits in a set of its own.
Look at every pair of integers in the interval. If the two integers have a common prime factor that is at least , merge the two sets that contain them.
Report how many sets are left when the process ends.
Input
The first line contains an integer , the number of test cases.
Each of the next lines contains three single-space-separated integers , and . and are the first and last integers of the interval, and is the value described above.
Limits
Output
For each test case, print one line of the form "Case #X: Y", where is the test case number starting from 1 and is the number of sets.