There are two small ants on Rikka's desk. If we consider Rikka's desk as a two-dimensional Cartesian coordinate system, both of them have coordinate (1,0). Now, Rikka places three obstacles on her desk: 1. y = 0, none of the two ants can walk cross this line. 2.y=abxy = frac{a}{b}xy=bax, only the second ant can walk cross this line. 3.y=cdxy = frac{c}{d}xy=dcx, only the first ant can walk cross this line. It's remarkable that it is allowed for the ants to stand exactly on the obstacles. For example, if a=b=c=d=1, then both of the ants can reach (1,0),(1,1),(2,1),(2,2) and none of them can reach (1,2),(2,3). Now, the ants start to move. Their strategy is very simple: In each second, let (x,y) be the current coordinate of one ant, if it can reach , it will walk to this point, otherwise it will walk to .. The following image shows the first ant's path when a=3,b=2: Now, given a,b,c,d, let p1 be the first ant's path and p2 be the second ant's path. Rikka wants you to calculate the number of the points with integer coordinates which are on both p1 and p2.
There are two small ants on Rikka's desk. If we consider Rikka's desk as a two-dimensional Cartesian coordinate system, both of them have coordinate (1,0). Now, Rikka places three obstacles on her desk: 1. y = 0, none of the two ants can walk cross this line. 2. y=abx(a,b>0)y = frac{a}{b}x(a,b > 0)y=bax(a,b>0), only the second ant can walk cross this line. 3. y=cdx(c,d>0)y = frac{c}{d}x(c,d > 0)y=dcx(c,d>0), only the first ant can walk cross this line. It's remarkable that it is allowed for the ants to stand exactly on the obstacles. For example, if a=b=c=d=1, then both of the ants can reach (1,0),(1,1),(2,1),(2,2) and none of them can reach (1,2),(2,3). Now, the ants start to move. Their strategy is very simple: In each second, let (x,y) be the current coordinate of one ant, if it can reach (x,y+1), it will walk to this point, otherwise it will walk to (x+1,y).(Since ab,cd>0frac{a}{b},frac{c}{d} >0ba,dc>0, if the ant can reach (x,y), it can also reach (x+1,y)). The following image shows the first ant's path when a=3,b=2: Now, given a,b,c,d, let p1 be the first ant's path and p2 be the second ant's path. Rikka wants you to calculate the number of the points with integer coordinates which are on both p1 and p2.