Course Test · University: upper level

Number theory: RatMath answers

The same twenty exercises, answered with RatMath Core and the Shelf libraries only. The code below was run when this page was built; its output is shown as printed, and compared with the independent answer.

Agrees 20

Libraries used here: core, numtheory. In this code each library is in scope under its own name (linalg.det, stats.tTest), and Core's names (R, Rational, …) are in scope directly.

  1. 1.Bézout coefficientsAgrees
    Find gcd⁡(252,198)\gcd(252, 198) and integers x,yx, y with 252x+198y=gcd⁡(252,198)252x + 198y = \gcd(252, 198).
    Independent answer
    252=1⋅198+54252 = 1\cdot198 + 54, 198=3⋅54+36198 = 3\cdot54 + 36, 54=1⋅36+1854 = 1\cdot36 + 18, 36=2⋅1836 = 2\cdot18. So the gcd is 18, and back-substituting gives 18=4⋅252−5⋅19818 = 4\cdot252 - 5\cdot198.
    RatMath code
    numtheory.egcd(252, 198)
    Output
    { g: 18n, x: 4n, y: -5n }
    Every other numtheory function takes plain numbers, but egcd needs BigInts: egcd(252n, 198n) gives { g: 18n, x: 4n, y: -5n }.
    Fix: ratmath/numtheory#9, egcd, gcd, isqrt and friends read any whole number
  2. 2.Linear congruenceAgrees
    Solve 17x≡3(mod29)17x \equiv 3 \pmod{29}.
    Independent answer
    17⋅12=204=7⋅29+117\cdot12 = 204 = 7\cdot29 + 1, so 17−1≡1217^{-1} \equiv 12 and x≡36≡7(mod29)x \equiv 36 \equiv 7 \pmod{29}.
    RatMath code
    numtheory.solveLinear(17, 3, 29).solutions
    Output
    [7n]
  3. 3.Chinese remainder theoremAgrees
    Find the least positive xx with x≡2(mod3)x \equiv 2 \pmod 3, x≡3(mod5)x \equiv 3 \pmod 5, x≡2(mod7)x \equiv 2 \pmod 7.
    Independent answer
    x≡2(mod21)x \equiv 2 \pmod{21} from the first and third; 2,23,44,…2, 23, 44, \dots: 23 is 3 mod 53 \bmod 5. So x=23x = 23 (mod 105).
    RatMath code
    numtheory.crt([2, 3, 2], [3, 5, 7])
    Output
    { x: 23n, modulus: 105n }
  4. 4.Euler's totientAgrees
    Compute φ(360)\varphi(360).
    Independent answer
    360=23⋅32⋅5360 = 2^3\cdot3^2\cdot5: φ=360⋅12⋅23⋅45=96\varphi = 360\cdot\tfrac12\cdot\tfrac23\cdot\tfrac45 = 96.
    RatMath code
    numtheory.totient(360)
    Output
    96n
  5. 5.Fermat's little theoremAgrees
    Find 3100 mod 73^{100} \bmod 7.
    Independent answer
    36≡13^6 \equiv 1, 100=6⋅16+4100 = 6\cdot16 + 4, so 3100≡34=81≡43^{100} \equiv 3^4 = 81 \equiv 4.
    RatMath code
    numtheory.modPow(3, 100, 7)
    Output
    4n
  6. 6.Divisor functionsAgrees
    Compute σ(28)\sigma(28) and τ(28)\tau(28). Is 28 perfect?
    Independent answer
    Divisors 1, 2, 4, 7, 14, 28: τ=6\tau = 6, σ=56=2⋅28\sigma = 56 = 2\cdot28, so 28 is perfect.
    RatMath code
    [numtheory.sigma(28), numtheory.tau(28), numtheory.isPerfect(28)]
    Output
    [56n, 6n, true]
  7. 7.Möbius functionAgrees
    Compute μ(30)\mu(30) and μ(12)\mu(12).
    Independent answer
    30=2⋅3⋅530 = 2\cdot3\cdot5 has three distinct primes: μ=−1\mu = -1. 1212 has a square factor: μ=0\mu = 0.
    RatMath code
    [numtheory.mobius(30), numtheory.mobius(12)]
    Output
    [-1n, 0n]
  8. 8.Legendre symbolAgrees
    Evaluate (511)\left(\frac{5}{11}\right).
    Independent answer
    By reciprocity (511)=(115)=(15)=1\left(\frac5{11}\right) = \left(\frac{11}5\right) = \left(\frac15\right) = 1. (Indeed 42=16≡54^2 = 16 \equiv 5.)
    RatMath code
    numtheory.legendre(5, 11)
    Output
    1
  9. 9.Jacobi symbolAgrees
    Evaluate the Jacobi symbol (215)\left(\frac{2}{15}\right). Is 2 a square mod 15?
    Independent answer
    (23)(25)=(−1)(−1)=1\left(\frac23\right)\left(\frac25\right) = (-1)(-1) = 1, but 2 is not a square mod 3, so it is not a square mod 15: the Jacobi symbol 1 does not imply a square.
    RatMath code
    [numtheory.jacobi(2, 15), numtheory.sqrtsMod(2, 15)]
    Output
    [1, []]
  10. 10.Square roots mod pAgrees
    Solve x2≡10(mod13)x^2 \equiv 10 \pmod{13}.
    Independent answer
    62=36=2⋅13+106^2 = 36 = 2\cdot13 + 10, so x≡±6x \equiv \pm6, that is 6 and 7.
    RatMath code
    numtheory.sqrtsMod(10, 13)
    Output
    [6n, 7n]
  11. 11.Order of an elementAgrees
    Find the multiplicative order of 2 modulo 11.
    Independent answer
    The order divides 10. 22=42^2 = 4, 25=32≡10≢12^5 = 32 \equiv 10 \not\equiv 1, so the order is 10.
    RatMath code
    numtheory.multiplicativeOrder(2, 11)
    Output
    10n
  12. 12.Primitive rootsAgrees
    Find the least primitive root modulo 13.
    Independent answer
    24=16≡32^4 = 16 \equiv 3, 26=64≡12≡−12^6 = 64 \equiv 12 \equiv -1, so 212/2,212/3≠12^{12/2}, 2^{12/3} \ne 1: 2 has order 12 and is a primitive root.
    RatMath code
    numtheory.primitiveRoot(13)
    Output
    2n
  13. 13.Fermat numbersAgrees
    Factor F5=232+1F_5 = 2^{32} + 1.
    Independent answer
    Euler: 232+1=641⋅67004172^{32} + 1 = 641 \cdot 6700417 (both prime).
    RatMath code
    numtheory.formatFactors(numtheory.factor(2n ** 32n + 1n))
    Output
    641 · 6700417
  14. 14.Carmichael numbersAgrees
    Show 561 is composite but a560≡1(mod561)a^{560} \equiv 1 \pmod{561} for every aa coprime to 561.
    Independent answer
    561=3⋅11⋅17561 = 3\cdot11\cdot17, and 2,10,162, 10, 16 all divide 560 (Korselt), so the Carmichael function λ(561)=lcm⁡(2,10,16)=80\lambda(561) = \operatorname{lcm}(2, 10, 16) = 80 divides 560.
    RatMath code
    [numtheory.formatFactors(numtheory.factor(561)), numtheory.carmichael(561), 560 % Number(numtheory.carmichael(561))]
    Output
    ["3 · 11 · 17", 80n, 0]
  15. 15.Sums of two squaresAgrees
    Write 65 as a sum of two squares in every way (a≥b>0a \ge b > 0).
    Independent answer
    65=5⋅13=(22+12)(32+22)65 = 5\cdot13 = (2^2+1^2)(3^2+2^2): 65=82+12=72+4265 = 8^2 + 1^2 = 7^2 + 4^2.
    RatMath code
    numtheory.twoSquaresAll(65)
    Output
    [[8n, 1n], [7n, 4n]]
  16. 16.Linear Diophantine equationsAgrees
    Find all solutions of 3x+5y=473x + 5y = 47 in non-negative integers.
    Independent answer
    47−5y≡0(mod3)47 - 5y \equiv 0 \pmod 3 needs y≡1(mod3)y \equiv 1 \pmod 3: y=1,4,7y = 1, 4, 7 give x=14,9,4x = 14, 9, 4.
    RatMath code
    numtheory.nonNegativeSolutions(3, 5, 47).solutions
    Output
    [[4n, 7n], [9n, 4n], [14n, 1n]]
  17. 17.Frobenius numberAgrees
    Chicken nuggets come in boxes of 6, 9 and 20. What is the largest number that cannot be bought exactly?
    Independent answer
    44 = 24 + 20, 45 = 5·9, 46 = 6 + 40, 47 = 27 + 20, 48 = 8·6, 49 = 9 + 40 are all possible, and any later number adds 6 to one of these. 43 is not possible (43, 23 and 3 are not sums of 6s and 9s). Answer: 43.
    RatMath code
    numtheory.frobenius([6, 9, 20])
    Output
    43n
  18. 18.Continued fractions and Pell's equationAgrees
    Find the continued fraction of 13\sqrt{13}, and the smallest positive solution of x2−7y2=1x^2 - 7y^2 = 1.
    Independent answer
    13=[3;1,1,1,1,6‾]\sqrt{13} = [3; \overline{1, 1, 1, 1, 6}]. For D=7D = 7: 7=[2;1,1,1,4‾]\sqrt7 = [2; \overline{1,1,1,4}], convergent 8/38/3: 64−63=164 - 63 = 1, so (8,3)(8, 3).
    RatMath code
    const cf = numtheory.periodicContinuedFraction(numtheory.fromQuadratic(0, 1, 13, 1));
    const p = numtheory.pell(7);
    [cf.preperiod, cf.period, p.x, p.y]
    Output
    [[3n], [1n, 1n, 1n, 1n, 6n], 8n, 3n]
    Both algebraic.sqrt(13n) and the displayed quadratic representation give initial term 3 and repeating block 1, 1, 1, 1, 6. Check the Pell solution independently by computing 8² − 7·3² = 1.
    Fix: ratmath/algebraic#9, the arithmetic reads plain numbers, so sqrt(48) works
  19. 19.Legendre's formulaAgrees
    What is the largest power of 2 dividing 100!100!?
    Independent answer
    ⌊100/2⌋+⌊100/4⌋+⋯=50+25+12+6+3+1=97\lfloor 100/2\rfloor + \lfloor100/4\rfloor + \dots = 50 + 25 + 12 + 6 + 3 + 1 = 97.
    RatMath code
    numtheory.factorialValuation(100, 2)
    Output
    97
    factorialValuation applies Legendre's formula without building 100!100!.
    Fix: ratmath/numtheory#10, factorialValuation (Legendre's formula)
  20. 20.Prime countingAgrees
    How many primes are below 1000?
    Independent answer
    π(1000)=168\pi(1000) = 168.
    RatMath code
    numtheory.primePi(1000)
    Output
    168n