Dmitriy, remember that the sum of angles of regular polygon is 180(n-2),
where n is the number of it's angles.
The radius of circle is the half of polygon's diagonal + 1.0.
So the answer is 1.0/cos(pi*(n-2)/(2*n))+1.0, exceptions is 1, R will be 1.
And don't forget about precision it must be at least 6 digits.
If you still are having problems with it look at this:
https://github.com/oybek/timus/blob/master/1984.cpp