Redaksiya
Johnny English and Bof reach the final point simultaneously in time . Johnny English covers a distance , while Bof covers a distance . The ratio of the distances traveled is equal to the ratio of the speeds: .
Let's construct such paths constructively. For example, consider a route consisting of points: . Here, the coordinate is chosen to ensure that its value is non-negative (according to the problem's conditions, ).
The length of Johnny English's path is .
The length of Bof's path is .
If the speeds of Johnny English and Bof are the same, then the points and coincide, and according to the problem's conditions, there cannot be two identical points in a row on the route. In this case, as a solution, one could choose, for example, the following route: .
Algorithm realization
Read the input data.
scanf("%d %d", &q, &p);
If the speeds of Johnny English and Bof are the same, then they move from point to point .
if (q == p) { printf("2\n"); printf("%d %d\n", 0, 0); printf("%d %d\n", 1, 0); return 0; }
If , then the route consists of four points.
printf("4\n"); printf("%d %d\n", 0, 0); printf("%d %d\n", 2 * q, 0); printf("%d %d\n", 2 * q, p - q); printf("%d %d\n", 2 * q, 0);