#P13461. [GCJ 2008 #1B] Number Sets

    ID: 15336 远端评测题 3000ms 1024MiB 尝试: 0 已通过: 0 难度: 4 上传者: 标签>2008并查集素数判断,质数,筛法Google Code Jam

[GCJ 2008 #1B] Number Sets

题目描述

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

You are given the interval, and an integer PP. 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 PP, 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?

输入格式

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

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

输出格式

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

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

提示

Small dataset (10 Pts, Test set 1 - Visible)

  • 1C101 \leq C \leq 10
  • 1AB10001 \leq A \leq B \leq 1000
  • 2PB2 \leq P \leq B

Large dataset (25 Pts, Test set 2 - Hidden)

  • 1C1001 \leq C \leq 100
  • 1AB10121 \leq A \leq B \leq 10^{12}
  • BA+1000000B \leq A + 1000000
  • 2PB2 \leq P \leq B