# From Pari to SAGE

f(n,p)={d=ceil(log(2)/log(10)(n-1));s=lift(Mod(2,p)^(n-1));t=lift(Mod(10,p)^d);‌​u=lift(Mod((2s-1)*t+s-1,p));u}

v=[100000..101000]

forprime(q=1,10^7,z=select(m->f(m,q)==0,v);if(length(z)>0,v=setminus(v,z);print(‌​q," ",length(z)," ",length(v))))

This is a program for PARI. For numbers of the form (2^k-1)*10^d+2^(k-1)-1 where d is the number of decimal digits of 2^(k-1)-1 in the range k=[100000..101000], it displays numbers with no factor below 10^7. Can somebody translate this PARI program in a SAGE program?

edit retag close merge delete

Please format the code by selecting it and using the code (101010) button. Wrap inline code in backticks and LaTeX in dollar signs.

Sort by » oldest newest most voted Here is a more or less direct translation:

def f(n,p):
d = ceil(log(2)/log(10)*(n-1))
s = GF(p)(2)^(n-1)
t = GF(p)(10)^d
u = ((2*s-1)*t + s - 1).lift()
return u

v = set(srange(100000,101000+1))

for q in primes(10^7):
z = [m for m in v if f(m,q) == 0]
if len(z) > 0:
v -= set(z)
print q, len(z), len(v)

more