Ada Lovelace (1815-1852) was an English mathematician who was the first person to realize that computers could be much more than big calculators and published the first complex computer algorithm in 1843. She did this long before any computer existed to execute her algorithm as it was devised for the Analytical Engine which never got built. The algorithm, detailed in Note G of Sketch of The Analytical Engine Invented by Charles Babbage by Luigi Menabrea with notes by Ada Lovelace described how the Analytical Engine could calculate the Bernoulli numbers using a recursive algorithm, which you will reproduce here.

The Bernoulli numbers $B_n$ are a sequence of rational numbers (fractions) that tend to show up in many places in mathematics, and there are many ways of calculating them. One method is to calculate them recursively where calculating $B_n$ involves knowing $B_0, B_1, \dots, B_{n-1}$. A derivation of how Ada Lovelace came up with the formula is posted in the notes tab, but she essentially used the following formula $$ B_n = -\sum_{k=0}^{n-1} \frac{n!}{(n+1-k)!\cdot k!} B_k = -\sum_{k=0}^{n-1} \binom{n}{k} \frac{B_k}{n+1-k} $$ where $B_n$ is calculated from $B_0, B_1, \dots, B_{n-1}$. Here $\displaystyle \binom{n}{k} = \frac{n!}{k!(n-k)!}$ is a binomial coefficient, and $n! = n(n-1)(n-2)\cdots3\cdot2\cdot1$ is the factorial which is the product of all positive integers less than or equal to $n$. $B_0 = 1$ while there are two choices for $B_1$ corresponding to two conventions and we will choose $\displaystyle B_1 = -\frac{1}{2}$ which most modern textbooks use.

Diagram of an algorithm for the Analytical Engine for the computation of Bernoulli numbers, from Sketch of The Analytical Engine Invented by Charles Babbage by Luigi Menabrea with notes by Ada Lovelace. The steps are describing how the analytical engine would compute $B_8$, which she called $B_7$ in her notation. (Source: Wikimedia Commons)

Write a function that calculates $B_n$ and returns the numerator and denominator. If $B_n$ is negative, the minus sign should be included with the numerator.

Input: An integer $n$.

Output: The numerator and denominator of the $n^\textrm{th}$ Bernoulli number $B_n$. If $B_n$ is negative, the minus sign should be included with the numerator. If $B_n = 0$ then return a numerator of 0 and a denominator of 1.

Example 1 Input n: 8 Output numerator: -1 Output denominator: 30

Example 2 Input n: 3 Output numerator: 0 Output denominator: 1