Data update

This commit is contained in:
Ingy döt Net 2023-08-01 14:30:30 -07:00
parent 07c7092a52
commit 61b93a2cd1
313 changed files with 6160 additions and 346 deletions

View file

@ -0,0 +1,22 @@
begin % find elements of the Euclid-Mullin sequence: starting from 2, %
% the next element is the smallest prime factor of 1 + the product %
% of the previous elements %
integer product;
write( "2" );
product := 2;
for i := 2 until 8 do begin
integer nextV, p;
logical found;
nextV := product + 1;
% find the first prime factor of nextV %
p := 3;
found := false;
while p * p <= nextV and not found do begin
found := nextV rem p = 0;
if not found then p := p + 2
end while_p_squared_le_nextV_and_not_found ;
if found then nextV := p;
writeon( i_w := 1, s_w := 0, " ", nextV );
product := product * nextV
end for_i
end.

View file

@ -0,0 +1,24 @@
# find elements of the Euclid-Mullin sequence: starting from 2,
# the next element is the smallest prime factor of 1 + the product
# of the previous elements
BEGIN {
printf( "2" );
product = 2;
for( i = 2; i <= 8; i ++ )
{
nextV = product + 1;
# find the first prime factor of nextV
p = 3;
found = 0;
while( p * p <= nextV && ! ( found = nextV % p == 0 ) )
{
p += 2;
}
if( found )
{
nextV = p;
}
printf( " %d", nextV );
product *= nextV
}
}

View file

@ -15,7 +15,7 @@ var (
five = big.NewInt(5)
six = big.NewInt(6)
ten = big.NewInt(10)
max = big.NewInt(100000)
k100 = big.NewInt(100000)
)
func pollardRho(n, c *big.Int) *big.Int {
@ -51,7 +51,7 @@ func pollardRho(n, c *big.Int) *big.Int {
return d
}
func smallestPrimeFactorWheel(n *big.Int) *big.Int {
func smallestPrimeFactorWheel(n, max *big.Int) *big.Int {
if n.ProbablyPrime(15) {
return n
}
@ -82,13 +82,13 @@ func smallestPrimeFactorWheel(n *big.Int) *big.Int {
}
func smallestPrimeFactor(n *big.Int) *big.Int {
s := smallestPrimeFactorWheel(n)
s := smallestPrimeFactorWheel(n, k100)
if s != nil {
return s
}
c := big.NewInt(1)
s = new(big.Int).Set(n)
for n.Cmp(max) > 0 {
for {
d := pollardRho(n, c)
if d.Cmp(zero) == 0 {
if c.Cmp(ten) == 0 {
@ -96,20 +96,21 @@ func smallestPrimeFactor(n *big.Int) *big.Int {
}
c.Add(c, one)
} else {
// can't be sure PR will find the smallest prime factor first
if d.Cmp(s) < 0 {
s.Set(d)
}
n.Quo(n, d)
if n.ProbablyPrime(5) {
if n.Cmp(s) < 0 {
return n
// get the smallest prime factor of 'd'
factor := smallestPrimeFactorWheel(d, d)
// check whether n/d has a smaller prime factor
s = smallestPrimeFactorWheel(n.Quo(n, d), factor)
if s != nil {
if s.Cmp(factor) < 0 {
return s
} else {
return factor
}
return s
} else {
return factor
}
}
}
return s
}
func main() {

View file

@ -0,0 +1,20 @@
-- find elements of the Euclid-Mullin sequence: starting from 2,
-- the next element is the smallest prime factor of 1 + the product
-- of the previous elements
do
io.write( "2" )
local product = 2
for i = 2, 8 do
local nextV = product + 1
-- find the first prime factor of nextV
local p = 3
local found = false
while p * p <= nextV and not found do
found = nextV % p == 0
if not found then p = p + 2 end
end
if found then nextV = p end
io.write( " ", nextV )
product = product * nextV
end
end

View file

@ -0,0 +1,24 @@
function gcd(a,b)
while b~=0 do
a,b=b,a%b
end
return math.abs(a)
end
function pollard_rho(n)
local x, y, d = 2, 2, 1
local g = function(x) return (x*x+1) % n end
while d == 1 do
x = g(x)
y = g(g(y))
d = gcd(math.abs(x-y),n)
end
if d == n then return d end
return math.min(d, math.floor( n/d ) )
end
local ar, product = {2}, 2
repeat
ar[ #ar + 1 ] = pollard_rho( product + 1 )
product = product * ar[ #ar ]
until #ar >= 8
print( table.concat(ar, " ") )

View file

@ -0,0 +1,19 @@
// find elements of the Euclid-Mullin sequence: starting from 2,
// the next element is the smallest prime factor of 1 + the product
// of the previous elements
seq = [2]
product = 2
for i in range( 2, 8 )
nextV = product + 1
// find the first prime factor of nextV
p = 3
found = false
while p * p <= nextV and not found
found = nextV % p == 0
if not found then p = p + 2
end while
if found then nextV = p
seq.push( nextV )
product = product * nextV
end for
print seq.join( " ")

View file

@ -0,0 +1,18 @@
// find elements of the Euclid-Mullin sequence: starting from 2,
// the next element is the smallest prime factor of 1 + the product
// of the previous elements
see "2"
product = 2
for i = 2 to 8
nextV = product + 1
// find the first prime factor of nextV
p = 3
found = false
while p * p <= nextV and not found
found = ( nextV % p ) = 0
if not found p = p + 2 ok
end
if found nextV = p ok
see " " + nextV
product = product * nextV
next

View file

@ -0,0 +1,15 @@
def pollard_rho(n)
x, y, d = 2, 2, 1
g = proc{|x|(x*x+1) % n}
while d == 1 do
x = g[x]
y = g[g[y]]
d = (x-y).abs.gcd(n)
end
return d if d == n
[d, n/d].compact.min
end
ar = [2]
ar << pollard_rho(ar.inject(&:*)+1) until ar.size >= 16
puts ar.join(", ")

View file

@ -4,33 +4,9 @@ var zero = BigInt.zero
var one = BigInt.one
var two = BigInt.two
var ten = BigInt.ten
var max = BigInt.new(100000)
var k100 = BigInt.new(100000)
var pollardRho = Fn.new { |n, c|
var g = Fn.new { |x, y| (x*x + c) % n }
var x = two
var y = two
var z = one
var d = max + one
var count = 0
while (true) {
x = g.call(x, n)
y = g.call(g.call(y, n), n)
d = (x - y).abs % n
z = z * d
count = count + 1
if (count == 100) {
d = BigInt.gcd(z, n)
if (d != one) break
z = one
count = 0
}
}
if (d == n) return zero
return d
}
var smallestPrimeFactorWheel = Fn.new { |n|
var smallestPrimeFactorWheel = Fn.new { |n, max|
if (n.isProbablePrime(5)) return n
if (n % 2 == zero) return BigInt.two
if (n % 3 == zero) return BigInt.three
@ -47,23 +23,22 @@ var smallestPrimeFactorWheel = Fn.new { |n|
}
var smallestPrimeFactor = Fn.new { |n|
var s = smallestPrimeFactorWheel.call(n)
var s = smallestPrimeFactorWheel.call(n, k100)
if (s) return s
var c = one
s = n
while (n > max) {
var d = pollardRho.call(n, c)
while (true) {
var d = BigInt.pollardRho(n, 2, c)
if (d == 0) {
if (c == ten) Fiber.abort("Pollard Rho doesn't appear to be working.")
c = c + one
} else {
// can't be sure PR will find the smallest prime factor first
s = BigInt.min(s, d)
n = n / d
if (n.isProbablePrime(2)) return BigInt.min(s, n)
// get the smallest prime factor of 'd'
var factor = smallestPrimeFactorWheel.call(d, d)
// check whether n/d has a smaller prime factor
s = smallestPrimeFactorWheel.call(n/d, factor)
return s ? BigInt.min(s, factor) : factor
}
}
return s
}
var k = 16

View file

@ -2,45 +2,38 @@
import "./gmp" for Mpz
var max = Mpz.from(100000)
var k100 = Mpz.from(100000)
var smallestPrimeFactorWheel = Fn.new { |n|
var smallestPrimeFactorTrial = Fn.new { |n, max|
if (n.probPrime(15) > 0) return n
if (n.isEven) return Mpz.two
if (n.isDivisibleUi(3)) return Mpz.three
if (n.isDivisibleUi(5)) return Mpz.five
var k = Mpz.from(7)
var i = 0
var inc = [4, 2, 4, 2, 4, 6, 2, 6]
var k = Mpz.one
while (k * k <= n) {
if (n.isDivisible(k)) return k
k.add(inc[i])
k.nextPrime
if (k > max) return null
i = (i + 1) % 8
if (n.isDivisible(k)) return k
}
}
var smallestPrimeFactor = Fn.new { |n|
var s = smallestPrimeFactorWheel.call(n)
var s = smallestPrimeFactorTrial.call(n, k100)
if (s) return s
var c = Mpz.one
s = n.copy()
while (n > max) {
while (true) {
var d = Mpz.pollardRho(n, 2, c)
if (d.isZero) {
if (c == 100) Fiber.abort("Pollard Rho doesn't appear to be working.")
c.inc
} else {
// can't be sure PR will find the smallest prime factor first
s.min(d)
n.div(d)
if (n.probPrime(5) > 0) return Mpz.min(s, n)
// get the smallest prime factor of 'd'
var factor = smallestPrimeFactorTrial.call(d, d)
// check whether n/d has a smaller prime factor
s = smallestPrimeFactorTrial.call(n/d, factor)
return s ? Mpz.min(s, factor) : factor
}
}
return s
}
var k = 19
var k = 27
System.print("First %(k) terms of the EuclidMullin sequence:")
System.print(2)
var prod = Mpz.two