OFFSET
1,1
COMMENTS
Each step is x -> f(x) and y -> f(f(y)), until finding g = gcd(x-y, m) != 1, since then g is a factor of m (though if x = y is reached then merely g = m).
Even m are not considered since they would be always 1 step to reach x = 2, y = 4 with g = 2.
Sometimes this f finds a factor with less work than the more common x^2+1, as for instance at m = 4295229443 which is a(2147614721) = 3 steps and about 57 modular squares in the powering, as against x^2 + 1 taking 172 steps with 516 squares.
LINKS
EXAMPLE
For n = 117, m = 235 and the a(117) = 3 steps until finding g != 1 are
x = 1, 2, 4, 16,
y = 1 4, 206, 96,
with g = gcd(96-16, 235) = 5 in this case being a proper factor of m.
MAPLE
coprime := (a, b) -> NumberTheory:-AreCoprime(a, b):
a := proc(n) local m, c, x, y, f;
if n = 1 then return 2 fi;
m := 2*n + 1; x := 2; y := 4;
f := x -> 2 &^ x mod m;
for c while coprime(x - y, m) do
x := f(x); y := f(f(y));
od; c end:
seq(a(n), n = 1..81); # Peter Luschny, Jan 07 2025
PROG
(Python)
from math import gcd
def a(n):
m = 2*n+1
c, g, x, y = 0, 1, 1, 1
f = lambda x: pow(2, x, m)
while g == 1:
x = f(x)
y = f(f(y))
g = gcd(x - y, m)
c += 1
return c
print([a(n) for n in range(1, 82)])
CROSSREFS
KEYWORD
nonn,new
AUTHOR
Darío Clavijo, Jan 04 2025
STATUS
approved