Formula to calculate Single Speed Chain Length from Chainring Size, Cog Size, and Chainstay Length
http://www.parktool.com/blog/repair-help/chain-length-sizing

Scroll to the bottom, equation is there, you want the "Rigorous Equation".

Better solution: start with heltonbiker's question on the math stack and ask how to convert to chain length.

Happy Riding.