Nearby Gravitation
Time limit5sMemory limit128 MB
Count pairs of 3D points whose Euclidean distance is smaller than k for each test case.
Problem
In a system as crowded as the solar system, nobody wants to compute the gravity between two objects that sit very far apart, and the value comes out so small that the work is wasted anyway. So only pairs of objects closer than are worth looking at.
Given points in space, how many pairs of points are at a distance smaller than ?
Input
The input holds several test cases.
The first line of each test case has the number of points and the largest allowed distance . (, )
Each of the next lines has three integers , , , the coordinates of one point. ()
No point is given twice within one test case, and at most pairs of points are at a distance of or less.
The last line of the input has two zeros, and that line is not a test case.
Output
For each test case print the number of point pairs whose distance is smaller than , one count per line.