Johnny English and Bof reach the final point simultaneously in time . Johnny English covers a distance s_1 = p \cdot t, while Bof covers a distance s_2 = q \cdot t. The ratio of the distances traveled is equal to the ratio of the speeds: s_1 / s_2 = p / q.
Let's construct such paths constructively. For example, consider a route consisting of points: (0, 0) → (2q, 0) → (2q, p - q) → (2q, 0). Here, the coordinate p - q is chosen to ensure that its value is non-negative (according to the problem's conditions, q \le p).
The length of Johnny English's path is 2q + 2 * (p - q) = 2p.
The length of Bof's path is .
If the speeds of Johnny English and Bof are the same, then the points (2q, 0) and (2q, p - q) 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: (0, 0) → (1, 0).
Algorithm implementation
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 p \ne q, 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);