How to resolve the algorithm Zsigmondy numbers step by step in the Sidef programming language
How to resolve the algorithm Zsigmondy numbers step by step in the Sidef programming language
Table of Contents
Problem Statement
Zsigmondy numbers n to a, b, are the greatest divisor of an - bn that is coprime to am - bm for all positive integers m < n.
Suppose we set a = 2 and b = 1. (Zs(n,2,1)) For each n, find the divisors of an - bn and return the largest that is coprime to all of am - bm, where m is each of the positive integers 1 to n - 1. When n = 4, 24 - 14 = 15. The divisors of 15 are 1, 3, 5, and 15. For m = 1, 2, 3 we get 2-1, 22-12, 23-13, or 1, 3, 7. The divisors of 15 that are coprime to each are 5 and 1, (1 is always included). The largest coprime divisor is 5, so Zs(4,2,1) = 5.
When n = 6, 26 - 16 = 63; its divisors are 1, 3, 7, 9, 21, 63. The largest divisor coprime to all of 1, 3, 7, 15, 31 is 1, (1 is always included), so Zs(6,2,1) = 1.
If a particular an - bn is prime, then Zs(n,a,b) will be equal to that prime. 25 - 15 = 31 so Zs(5,2,1) = 31.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Zsigmondy numbers step by step in the Sidef programming language
Source code in the sidef programming language
func zsigmondy (a, b, c) {
var aexp = (0..c -> map {|k| a**k })
var bexp = (0..c -> map {|k| b**k })
var z = []
for n in (1 .. c) {
divisors(aexp[n] - bexp[n]).flip.each {|d|
1 ..^ n -> all {|k|
aexp[k] - bexp[k] -> is_coprime(d)
} && (z << d; break)
}
}
return z
}
for name,a,b in ([
'A064078: Zsigmondy(n,2,1)', 2,1,
'A064079: Zsigmondy(n,3,1)', 3,1,
'A064080: Zsigmondy(n,4,1)', 4,1,
'A064081: Zsigmondy(n,5,1)', 5,1,
'A064082: Zsigmondy(n,6,1)', 6,1,
'A064083: Zsigmondy(n,7,1)', 7,1,
'A109325: Zsigmondy(n,3,2)', 3,2,
'A109347: Zsigmondy(n,5,3)', 5,3,
'A109348: Zsigmondy(n,7,3)', 7,3,
'A109349: Zsigmondy(n,7,5)', 7,5,
].slices(3)) {
say ("\n#{name}:\n", zsigmondy(a, b, 20))
}
You may also check:How to resolve the algorithm Stair-climbing puzzle step by step in the AWK programming language
You may also check:How to resolve the algorithm Find largest left truncatable prime in a given base step by step in the Kotlin programming language
You may also check:How to resolve the algorithm Price fraction step by step in the AppleScript programming language
You may also check:How to resolve the algorithm Non-continuous subsequences step by step in the R programming language
You may also check:How to resolve the algorithm Closest-pair problem step by step in the AWK programming language