Tunnelling the Earth

Time limit1sMemory limit128 MB

Summary
For each pair of points given by latitude and longitude, print the difference between the great-circle surface distance and the straight-line tunnel distance, rounded to the nearest metre.
Level

Medium4 of 10

Topics
Geometry, Math, Implementation
Solved
No attempts yet

Problem

There are many ways to move people from place to place: cars, bikes, boats, trains, planes, and so on. For very long distances people usually fly, but a plane has to follow the curved surface of the Earth. The trip would be shorter if the traveller went in a straight line from one point to the other through a tunnel bored through the Earth.

For example, travelling from Waterloo to Cairo covers 92935219293521 metres along the great-circle route over the surface, but only 84911888491188 metres along the straight line through the Earth.

Assume the Earth is a perfect sphere with radius 63710096371009 metres.

Input

The first line contains a single integer, the number of test cases. Each test case is one line with four floating-point numbers: the latitude and longitude of the origin, followed by the latitude and longitude of the destination, all in degrees. Positive values mean North latitude and East longitude; negative values mean South latitude and West longitude.

Output

For each test case, output one line with a single integer: the difference between the great-circle distance over the surface and the straight-line distance through the Earth, in metres, rounded to the nearest integer.

Examples1

  1. Example 1

    Input
    1
    43.466667 -80.516667 30.058056 31.228889
    
    Expected output
    802333