QOJ.ac

QOJ

Time Limit: 10 s Memory Limit: 1024 MB Total points: 25

#5758. Number Sets

Statistics

Problem

You start with a sequence of consecutive integers. You want to group them into sets.

You are given the interval, and an integer P. Initially, each number in the interval is in its own set.

Then you consider each pair of integers in the interval. If the two integers share a prime factor which is at least P, then you merge the two sets to which the two integers belong.

How many different sets there will be at the end of this process?

Input

One line containing an integer C, the number of test cases in the input file.

For each test case, there will be one line containing three single-space-separated integers A, B, and P. A and B are the first and last integers in the interval, and P is the number as described above.

Output

For each test case, output one line containing the string "Case #X: Y" where X is the number of the test case, starting from 1, and Y is the number of sets.

Limits

Time limit: 30 10 seconds per test set.

Memory limit: 1GB.

Small dataset (Test set 1 - Visible; 10 Points)

1 ≤ C ≤ 10

1 ≤ AB ≤ 1000

2 ≤ PB

Large dataset (Test set 2 - Hidden; 15 Points)

1 ≤ C ≤ 100

1 ≤ AB ≤ 1012

BA + 1000000

2 ≤ PB

Sample

2
10 20 5
10 20 3
Case #1: 9
Case #2: 7
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.