NN and the Optical Illusion
From Codeforces. Tangent circles. Solve the geometry problem "NN and the Optical Illusion".
Examples
Input: [3,1]
Output: 6.464101615137752
Input: [3,2]
Output: 12.928203230275503
Hints
Outer circle centers form a regular n-gon around inner center. Each outer center is distance R+r from inner center; adjacent outer centers are distance 2r apart (tangent).
Law of cosines on isosceles triangle: (2r)² = (R+r)² + (R+r)² − 2(R+r)² cos(2π/n). Simplify using 1−cosθ = 2 sin²(θ/2) → r = R·sin(π/n) / (1−sin(π/n)).
As n→2, sin(π/n)→1, denominator → 0, solution blows up — output instability for small n. For large n, r ≈ Rπ/n. Use double precision throughout.
NN and the Optical Illusion
**From Codeforces.** Tangent circles. Solve the geometry problem "NN and the Optical Illusion".