How to resolve the algorithm Jacobi symbol step by step in the Wren programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Jacobi symbol step by step in the Wren programming language
Table of Contents
Problem Statement
The Jacobi symbol is a multiplicative function that generalizes the Legendre symbol. Specifically, the Jacobi symbol (a | n) equals the product of the Legendre symbols (a | p_i)^(k_i), where n = p_1^(k_1)p_2^(k_2)...*p_i^(k_i) and the Legendre symbol (a | p) denotes the value of a ^ ((p-1)/2) (mod p) If n is prime, then the Jacobi symbol (a | n) equals the Legendre symbol (a | n). Calculate the Jacobi symbol (a | n).
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Jacobi symbol step by step in the Wren programming language
Source code in the wren programming language
import "./fmt" for Fmt
var jacobi = Fn.new { |a, n|
if (!n.isInteger || n <= 0 || n%2 == 0) {
Fiber.abort("The 'n' parameter must be an odd positive integer.")
}
a = a % n
var result = 1
while (a != 0) {
while (a%2 == 0) {
a = a / 2
var nm8 = n % 8
if ([3, 5].contains(nm8)) result = -result
}
var t = a
a = n
n = t
if (a%4 == 3 && n%4 == 3) result = -result
a = a % n
}
return (n == 1) ? result : 0
}
System.print("Table of jacobi(a, n):")
System.print("n/a 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15")
System.print("---------------------------------------------------------------")
var n = 1
while (n < 31) {
Fmt.write("$3d", n)
for (a in 1..15) Fmt.write("$4d", jacobi.call(a, n))
System.print()
n = n + 2
}
You may also check:How to resolve the algorithm Sorting algorithms/Radix sort step by step in the 11l programming language
You may also check:How to resolve the algorithm Find the intersection of two lines step by step in the MATLAB programming language
You may also check:How to resolve the algorithm Check that file exists step by step in the ooRexx programming language
You may also check:How to resolve the algorithm Loops/Continue step by step in the Icon and Unicon programming language
You may also check:How to resolve the algorithm Semiprime step by step in the EasyLang programming language