If yours is one of the estimated 2.8 million British households planning to pick up a Christmas tree this weekend, then the hard bit is still ahead of you: working out how to decorate it. Fortunately, there is an app for that.

The formula for dressing the perfect tree, solving one of the last mathematical enigmas, was worked out by students from Sheffield University harnessing the magical power of pi.

Their online calculator will tell you how many baubles you need, the amount of tinsel, the length of the lights and even the height of the fairy on top.

The formula for lighting is simple: take the height of your tree in centimetres and multiply it by pi (approximately 3.14). So a tree that is 180cm, or around 6ft, tall will need 5.65 metres of lights. Equally, its pretty easy to calculate the height of the fairy: it should be one-tenth the height of your tree

The formulas were worked out in 2012 by Nicole Wrightham and Alex Craig, who were then members of the Sheffield University Maths Society (SUMS). “We hope they’ll play a part in making Christmas a bit easier for everyone,” Ms Wrightham said.

Scroll down to calculate what is needed for your perfect Christmas tree