There is a trigonometric identity (angle sum or angle difference) for cosine that looks like this:
cos(x-y) = cos(x)cos(y) + sin(x)sin(y)
In your example, x=3pi/7 and y=2pi/21
Therefore, we can rewrite the whole expression as:
cos(3pi/7 - 2pi/21) which = cos(9pi/21 - 2pi/21) = cos(7pi/21) = cos(pi/3) = 1/2
In your case, cos(pi/A)=cos(pi/3) so A=3 and B/2 = 1/2 so B=1.
Does that make sense? Let me know if you have any further questions!