Cameras as Invigilators

It is now 2040 AD. Gone are the days when thousands of teachers spent their precious time in exam halls as invigilators. Now exams are conducted in large square shaped rooms and two high precision cameras are placed in two corners of that room. Such a (6 × 6) exam room is shown on the left and this room can accommodate only (7 × 7) 49 students. But as there are cameras on the two upper corners so actually there is sitting arrangements for 49 − 2 = 47 students. But actual exam rooms can be square shaped and very large. So in general an (n × n) exam room has sitting arrangement for students. For this problem, n can be as large as 5000. As the room is very large and the students sit in grid pattern and far away from one another so the students and two cameras can be considered as points. The two cameras are high precision cameras and they can pin point each student very accurately. If the angular distance between two points is zero the camera considers that they are at the same line with the camera, but here lies the biggest bug of the camera which will be explained below. Figure 1: Figure 2: The camera can reasonably accurately decide whether two points are at the same line with respect to the camera. For example, in the picture on the left, point B, C and the camera at the upper left corner (Camera 1) is at the same line and the camera can detect it. Point A and B makes an angle θ (θ >> 0) with this camera so A B and C are not at the same line. But if the value of is very small then the camera can wrongly think that A, B and the Camera are at the same line and that is when this Camera will not function well as an invigilator. Then these two points will become troublesome points. For this problem θ is expressed as tan−1(k1), here n2 ≤ k ≤ 2n2. The range of k is such because when the room is large the exam authority can afford to buy higher precision cameras (Or cameras with more accuracy). To reduce the number of troublesome points, a 2nd Camera is installed at the upper right corner (Camera 2). Now a point that is troublesome for Camera 1 may not be troublesome for Camera 2. But still there may be some points which are troublesome for both the cameras. The figure on the right can be used to explain this scenario. We can see that point C and D makes a very small angle with Camera 1. So C and D may be considered troublesome for Camera 1. On the other hand, point C and E makes very small angle with Camera 2. So these two can be considered troublesome with respect to Camera 2. So point C is troublesome with respect to both the cameras. Given the size of the examination hall and value of k your job is to find out the number points or locations that are troublesome for both the cameras.

2/2 Input First line of the input file contains a positive integer T (T ≤ 10) which denotes the number of lines to follow. Each following line contains two integers n (10 ≤ n ≤ 5000) and k (n2 ≤ k ≤ 2n2). That means you have to consider an examination hall that can be represented as (n×n) grid, and there are two cameras (one at the upper left corner and the other at the upper right corner) and examinees sit on all other lattice points that are not outside the exam hall. And both the cameras have the defect that if two points or locations have angular distance less than tan−1(k1) with respect to the camera, it considers them collinear with the camera and both of them becomes troublesome points. Output For each test case you should produce one line of output which contains an integer T which denotes the total number of points that are troublesome with respect to both the cameras. Sample Input 2 100 10000 1000 1500000 Sample Output 30 0