Euclid-Mullin sequence: Difference between revisions

→‎{{header|Go}}: Aligned with changes to Wren version of which it's a translation. No change in runtime.
m (→‎{{header|Wren}}: Removed stray '>')
(→‎{{header|Go}}: Aligned with changes to Wren version of which it's a translation. No change in runtime.)
Line 212:
six = big.NewInt(6)
ten = big.NewInt(10)
max k100 = big.NewInt(100000)
)
 
Line 248:
}
 
func smallestPrimeFactorWheel(n, max *big.Int) *big.Int {
if n.ProbablyPrime(15) {
return n
Line 279:
 
func smallestPrimeFactor(n *big.Int) *big.Int {
s := smallestPrimeFactorWheel(n, k100)
if s != nil {
return s
Line 285:
c := big.NewInt(1)
s = new(big.Int).Set(n)
for n.Cmp(max) > 0 {
d := pollardRho(n, c)
if d.Cmp(zero) == 0 {
Line 293:
c.Add(c, one)
} else {
// can't be sure PR will findget the smallest prime factor firstof 'd'
iffactor d.Cmp:= smallestPrimeFactorWheel(s)d, < 0 {d)
// check whether s.Set(n/d) has a smaller prime factor
s = smallestPrimeFactorWheel(n.Quo(n, d), factor)
}
n.Quo(n,if d)s != nil {
if ns.ProbablyPrimeCmp(5factor) < 0 {
if n.Cmp(s) < 0 {return s
} else return n{
return factor
}
} else return s{
} return factor
}
}
}
return s
}
 
9,485

edits