Problem Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=3884
The problem states that, a billiard table of size S*S and a billiard ball at point (x1,y1) is given. There is another point given at (x2,y2) and when we shoot the ball it goes through the second point. So what is minimum number of times the ball will hit horizontal or vertical sides before returning to the initial point? For more details/constraints please visit the problem link.
What is the idea/approach to solve this problem? Help appreciated.
I think the best thing to do is reading the editorial of SRM 626, hard problem of div1. It starts with the main trick of this problem.