def factorize_trial(n, primes):
    """Factorizing n"""
    if miller_rabin(n):
        return n
    result = []
    for p in primes:
        while n % p == 0:
            result.append(p)
            n //= p
        if miller_rabin(n):
            result.append(n)
            break
    return result
示例#2
0
def A0(n):

    for k in xrange(2, 17):

        x = repunit(k)
        if miller_rabin(x): continue
        f = RetFact(x)
        if n in f:
            return k
    return 0
def A0(n):
  
  for k in xrange(2,17):
    
    x = repunit(k)
    if miller_rabin(x):continue
    f = RetFact(x)
    if n in f:
      return k
  return 0
def PollardRho(n):
    if miller_rabin(n):
        return n
    out = 0
    i = 0
    xi = random.randint(0,n-1)
    xi = 5
    k = 2
    y = xi
    while True:
        i = i + 1
        xi = ((xi ** 2) + 1) % n
        d = gcd(y - xi,n)
        if d != 1 and d != n:
            if miller_rabin(d):
                out = d
                break
        if i == k:
            y = xi
            k = 2 * k
    return out
def rho(n):
    if miller_rabin(n):
        return n
    def g(x, m):
        return (x*x - 1) % m
    x = 2
    y = 2
    d = 1
    while d == 1:
        x = g(x, n)
        y = g(g(y, n), n)
        d = gcd(abs(x - y), n)
    if d == n:
        return False
    else:
        return d
for i in xrange(2, 9):

    x = combinations(l, i)

    for p in x:

        xx = permutations(p)

        for xxx in xx:

            #print xxx
            qp = ''.join(str(i) for i in xxx)
            n = int(qp)
            if len(qp) != len(set(qp)): continue
            if miller_rabin(n):  #IsPrime(n):
                #print n
                d[i] += [qp]

ctr = 0

#print d[8]
#print
#print len(d[8])
#exit()

a1 = d[1]
b1 = d[2]
c1 = d[3]
d1 = d[4]
e1 = d[5]
for w in xrange(2,10):
  d[w]=[]

for i in xrange(2,9):

  x = combinations(l,i)

  for p in x:

    xx = permutations(p)
  
    for xxx in xx:
      qp = ''.join(str(i) for i in xxx)
      n = int(qp)
      if len(qp)!=len(set(qp)):continue
      if miller_rabin(n): 
        #print n
        d[i]+= [qp]

ctr=0

a1 = d[1]
b1 = d[2]
c1 = d[3]
d1 = d[4]
e1 = d[5]
f1 = d[6]
g1 = d[7]
h1 = d[8]

zz,zz1,zz2,zz3,zz4,zz5,zz6,zz7='','','','','','','',''
示例#8
0
            return k
    return 0


def A(n, d):

    for c in d:
        if n in d[c]:
            return c
    return 0


d = {}
for k in xrange(2, 21):
    x = repunit(k)
    if miller_rabin(x):
        d[k] = [x]
        continue
    f = RetFact(x)
    d[k] = f

print d
print

for n in xrange(3, 20):
    if gcd(n, 10) != 1: continue
    print n,
    print A(n, d)

# 11111111111111111  11111111111111111
# for i in xrange(10**6,10**6+10*3):
for i in xrange(2,9):

  x = combinations(l,i)


  for p in x:

    xx = permutations(p)
  
    for xxx in xx:

    #print xxx
      qp = ''.join(str(i) for i in xxx)
      n = int(qp)
      if len(qp)!=len(set(qp)):continue
      if miller_rabin(n):   #IsPrime(n):
        #print n
        d[i]+= [qp]

ctr=0

#print d[8]
#print
#print len(d[8])
#exit()

a1 = d[1]
b1 = d[2]
c1 = d[3]
d1 = d[4]
e1 = d[5]
示例#10
0
for w in xrange(2, 10):
    d[w] = []

for i in xrange(2, 9):

    x = combinations(l, i)

    for p in x:

        xx = permutations(p)

        for xxx in xx:
            qp = ''.join(str(i) for i in xxx)
            n = int(qp)
            if len(qp) != len(set(qp)): continue
            if miller_rabin(n):
                #print n
                d[i] += [qp]

ctr = 0

a1 = d[1]
b1 = d[2]
c1 = d[3]
d1 = d[4]
e1 = d[5]
f1 = d[6]
g1 = d[7]
h1 = d[8]

zz, zz1, zz2, zz3, zz4, zz5, zz6, zz7 = '', '', '', '', '', '', '', ''
示例#11
0
    f = RetFact(x)
    if n in f:
      return k
  return 0

def A(n,d):

  for c in d:
   if n in d[c]:
     return c
  return 0 
  
d={}
for k in xrange(2,21):
  x = repunit(k)
  if miller_rabin(x):
    d[k]=[x]  
    continue 
  f = RetFact(x)
  d[k]=f
  
print d
print  
  
for n in xrange(3, 20):
  if gcd(n,10) != 1: continue
  print n,
  print A(n,d)
  
# 11111111111111111  11111111111111111
# for i in xrange(10**6,10**6+10*3):