Problem D
Flower Garden

Due to the high cost of flowers in Alberta, Yraglac decided it would be a good idea to plant his own flower garden instead of buying flowers for his girlfriend. We can model his flower garden on a two-dimensional grid, where the position of each flower is given by an $(x,y)$ coordinate. Today, Yraglac decided it would be a good idea to water his flowers one by one, starting at the origin $(0,0)$ and walking to each flower. He will take the shortest path at each step. However, it turns out that Yraglac has an important meeting today and has a limited amount of time available to water the flowers. Thus, he has ranked all of the flowers in his garden from most to least important and will water them in that order. For religious reasons, the number of flowers watered by Yraglac must be a prime number, or zero. Help Yraglac find the maximum number of flowers he can water.


The first line contains a single integer $T \leq 10$ giving the number of test cases. Each test case starts with a line containing an integer $N$ ($1 \leq N \leq 20\, 000$), the number of flowers in the garden, and an integer $D$ ($0 \leq D \leq 10^9$), the maximum total distance that can be travelled by Yraglac. The next $N$ lines contain two integers $x_ i$ and $y_ i$ ($-500 \leq x_ i,y_ i \leq 500$), the coordinates of the $i$th flower. The flowers are ordered from most to least important. Every flower has a different position, and there will not be a flower at the origin $(0,0)$.


For each test case, output a single line containing the maximum number of flowers that Yraglac can water.

Sample Input 1 Sample Output 1
2 1
0 1
1 0
2 2
0 1
1 0
2 3
0 1
1 0
CPU Time limit 3 seconds
Memory limit 1024 MB
Statistics Show
License For educational use only

Please log in to submit a solution to this problem

Log in