Google Code Jam/Number sets

From HaskellWiki
< Google Code Jam
Revision as of 09:38, 31 July 2008 by Paolino (talk | contribs) (0)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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

Small dataset

1 <= C <= 10
1 <= A <= B <= 1000
2 <= P <= B

Large dataset

1 <= C <= 100
1 <= A <= B <= 1012
B <= A + 1000000
2 <= P <= B

Sample

Input

2
10 20 5
10 20 3

Output

Case #1: 9
Case #2: 7