code: def bernfrac(n):
      r"""
      Returns a tuple of integers `(p, q)` such that `p/q = B_n` exactly,
      where `B_n` denotes the `n`-th Bernoulli number. The fraction is
      always reduced to lowest terms. Note that for `n > 1` and `n` odd,
      `B_n = 0`, and `(0, 1)` is returned.
  
      **Examples**
  
      The first few Bernoulli numbers are exactly::
  
          >>> from mpmath import *
          >>> for n in range(15):
          ...     p, q = bernfrac(n)
          ...     print("%s %s/%s" % (n, p, q))
          ...
          0 1/1
          1 -1/2
          2 1/6
          3 0/1
          4 -1/30
          5 0/1
          6 1/42
          7 0/1
          8 -1/30
          9 0/1
          10 5/66
          11 0/1
          12 -691/2730
          13 0/1
          14 7/6
  
      This function works for arbitrarily large `n`::
  
          >>> p, q = bernfrac(10**4)
          >>> print(q)
          2338224387510
          >>> print(len(str(p)))
          27692
          >>> mp.dps = 15
          >>> print(mpf(p) / q)
          -9.04942396360948e+27677
          >>> print(bernoulli(10**4))
          -9.04942396360948e+27677
  
      .. note ::
  
          :func:`~mpmath.bernoulli` computes a floating-point approximation
          directly, without computing the exact fraction first.
          This is much faster for large `n`.
  
      **Algorithm**
  
      :func:`~mpmath.bernfrac` works by computing the value of `B_n` numerically
      and then using the von Staudt-Clausen theorem [1] to reconstruct
      the exact fraction. For large `n`, this is significantly faster than
      computing `B_1, B_2, \ldots, B_2` recursively with exact arithmetic.
      The implementation has been tested for `n = 10^m` up to `m = 6`.
  
      In practice, :func:`~mpmath.bernfrac` appears to be about three times
      slower than the specialized program calcbn.exe [2]
  
      **References**
  
      1. MathWorld, von Staudt-Clausen Theorem:
         http://mathworld.wolfram.com/vonStaudt-ClausenTheorem.html
  
      2. The Bernoulli Number Page:
         http://www.bernoulli.org/
  
      """
      n = int(n)
      if n < 3:
          return [(1, 1), (-1, 2), (1, 6)][n]
      if n & 1:
          return (0, 1)
      q = 1
      for k in list_primes(n + 1):
          if not (n % (k - 1)):
              q *= k
      prec = bernoulli_size(n) + int(math.log(q, 2)) + 20
      b = mpf_bernoulli(n, prec)
      p = mpf_mul(b, from_int(q))
      pint = to_int(p, round_nearest)
      return (pint, q)
  
imports: import math
  import sys
  from .backend import xrange
  from .backend import MPZ, MPZ_ZERO, MPZ_ONE, MPZ_THREE, gmpy
  from .libintmath import list_primes, ifac, ifac2, moebius
  from .libmpf import round_floor, round_ceiling, round_down, round_up, round_nearest, round_fast, lshift, sqrt_fixed, isqrt_fast, fzero, fone, fnone, fhalf, ftwo, finf, fninf, fnan, from_int, to_int, to_fixed, from_man_exp, from_rational, mpf_pos, mpf_neg, mpf_abs, mpf_add, mpf_sub, mpf_mul, mpf_mul_int, mpf_div, mpf_sqrt, mpf_pow_int, mpf_rdiv_int, mpf_perturb, mpf_le, mpf_lt, mpf_gt, mpf_shift, negative_rnd, reciprocal_rnd, bitcount, to_float, mpf_floor, mpf_sign, ComplexResult
  from .libelefun import constant_memo, def_mpf_constant, mpf_pi, pi_fixed, ln2_fixed, log_int_fixed, mpf_ln2, mpf_exp, mpf_log, mpf_pow, mpf_cosh, mpf_cos_sin, mpf_cosh_sinh, mpf_cos_sin_pi, mpf_cos_pi, mpf_sin_pi, ln_sqrt2pi_fixed, mpf_ln_sqrt2pi, sqrtpi_fixed, mpf_sqrtpi, cos_sin_fixed, exp_fixed
  from .libmpc import mpc_zero, mpc_one, mpc_half, mpc_two, mpc_abs, mpc_shift, mpc_pos, mpc_neg, mpc_add, mpc_sub, mpc_mul, mpc_div, mpc_add_mpf, mpc_mul_mpf, mpc_div_mpf, mpc_mpf_div, mpc_mul_int, mpc_pow_int, mpc_log, mpc_exp, mpc_pow, mpc_cos_pi, mpc_sin_pi, mpc_reciprocal, mpc_square, mpc_sub_mpf
label_desc: Use image node_id 11 for calling a global function with example usage: bernfrac(n) and returns: pint,  q, list, int,  int