Esempio n. 1
0
def main():
    lst = prepare_lst()
    result = {10}
    for a in sorted(lst):
        for addition in ADDITIONS:
            if not euler.miller_rabin(a * a + addition):
                break
        else:
            for addition in (19, 21):
                if euler.miller_rabin(a * a + addition):
                    break
            else:
                result.add(a)
    return sum(result)
Esempio n. 2
0
def main():
    total = 0
    i = 0
    for n in itertools.count(4):
        if (n & 1 and n % 5 and not euler.miller_rabin(n)
                and not (n - 1) % find(n)):
            i += 1
            total += n
            if i == LIMIT:
                break
    return total
Esempio n. 3
0
def main():
    prime_list = euler.prime_list(10**6)
    masks = collections.defaultdict(int)
    for prime in prime_list:
        for mask in all_masks(prime):
            masks[mask] += 1
            if masks[mask] == 8:
                start = 1 if mask.startswith('*') else 0
                for i in range(start, 10):
                    n = int(mask.replace('*', str(i)))
                    if euler.miller_rabin(n):
                        return n
    return 0
Esempio n. 4
0
def main():
    diff = 2
    primes = 3
    total = 5
    ratio = primes / total
    temp = 9
    while ratio >= 0.1:
        diff += 2
        for _ in range(3):
            temp += diff
            if euler.miller_rabin(temp):
                primes += 1
        temp += diff
        total += 4
        ratio = primes / total
    return diff + 1
Esempio n. 5
0
def main():
    last = 0
    for i in range(100000):
        s = str(i * 56789)
        if s.endswith('99999'):
            last = i
    last_digit_sum = sum((9 * i) % 10 for i in range(10))
    for i in range(
            int(round(1 / 0.00000000138, -5)) + last,
            int(round(1 / 0.00000000137, -5)),
            10 ** 5
    ):
        if euler.miller_rabin(i) and euler.prime_cycle_length(i) == i - 1:
            n = i - 1
            result = last_digit_sum * (n // 10)
            for j in range(n % 10):
                result += (9 * j) % 10
            return result
    return 0
Esempio n. 6
0
def main():
    total = 0
    lst = list(range(LIMIT1))
    lst[1] = 0
    nums = [2 * n * n - 1 for n in range(1000)]
    for prime in euler.prime_list(1000):
        for rest in range(1, prime):
            num = nums[rest]
            if not num % prime:
                if num == prime:
                    total += 1
                for i in range(rest, LIMIT1, prime):
                    lst[i] = 0
    for n in lst:
        if n:
            num = 2 * n * n - 1
            if euler.miller_rabin(num):
                total += 1
            for i in range(n, LIMIT1, num):
                lst[i] = 0
    return total
Esempio n. 7
0
def s_func(digit):
    for m in range(LIMIT, -1, -1):
        result = 0
        for indices in itertools.combinations(range(LIMIT), m):
            mask = MASK.copy()
            for index in indices:
                mask[index] = digit
            for numbers in itertools.product(range(10), repeat=LIMIT - m):
                new_mask = mask.copy()
                for number in numbers:
                    new_mask[new_mask.index('*')] = number
                if new_mask[0] == 0 or new_mask.count(digit) != m:
                    continue
                n = 0
                for number in new_mask:
                    n = n * 10 + number
                if euler.miller_rabin(n):
                    result += n
        if result:
            return result
    return 0
  
F,Phi=Factor(10000001)
  
#print len(Phi)

def chain(n):

  ctr=1
  while n > 1:
    n = Phi[n]
    ctr +=1
  return ctr

summ=0
for i in xrange(8900000,10000001):
  if miller_rabin(i):
    l = chain(i)
    if l == 25:
      print i,l,F[i]
      summ+=i
print "sum is", summ
print time()-st








Esempio n. 9
0
def main():
    return sum(1 for n in range(1, (int((LIMIT / 2)**0.5)))
               if euler.miller_rabin(2 * n * n + 2 * n + 1))
Esempio n. 10
0
def pseudo_fortunate_number(n):
    return next(
        2 + i
        for i in itertools.count()
        if euler.miller_rabin(n + 2 + i)
    )
Esempio n. 11
0
    #print x
    if x<101:
      l.append(x)
	  
l = sorted(l)
print l

for k in xrange(2,6):
  c = combinations(l,k)

  for f in c:
    if gcd2(f):
      p = sum(f)

      if p>100:continue
      print k,f,p
      if miller_rabin(p):
        #print "prime ",f[0],f[1], p
        if p not in d :
          d[p]=1
        else:
          d[p]=d[p]+1
	  
summ = 0
for p in d:
  if d[p]==1:summ += p;print p
print summ

print
print d
#print sorted(d)
Esempio n. 12
0
                    f[i].append(p)
            if f[p] == []: f[p] = [p]
    return f


from time import time
st = time()
N = 1 * 10**7
print "factoring integers up to ", N
#F=FactorSieve(N)
print "factor sieve complete and hogging memory..."
ctr = 0
plist = []
for j in xrange(100000, 200000):
    i = j
    if miller_rabin(i): continue
    f = RetFact(i)
    if len(f) == 1: continue
    A = isAchilles(f)
    if not A: continue
    phiA = Phi(i, f)
    #fphi=RetFact(phiA)
    fphi = RetFact(phiA)
    B = isAchilles(fphi)
    if not B: continue
    #if A and B and (set(f)==set([2,3]) or set(f)==set([3,2])): print i, f,":",phiA, fphi
    #if A and B and (set(f)==set([2,3])): print i, f,",",f.count(2),f.count(3),":",phiA, fphi
    #if A and B: print i, len(set(f)),":", f ,":",fphi #,",",f.count(2),f.count(3),":",phiA, fphi
    if A and B: print f[-1], "<", i, ":", f, ": ", RetFact(f[-1] - 1)
    ctr += 1
    plist.append(f[-1])
Esempio n. 13
0
#print F
print time()-st
exit()

summ=0
x=20000000
y=5000000
z=5000000
for x in xrange(20000000,15000000,-1):
 
  if x%z==0:
    v=x/z
    z-=1
    summ += sum(RetFact(v))
    continue
  elif miller_rabin(x):
    summ += x
    continue
  else:
    summ += sum(RetFact(x))    
    
    

 
 
 
 
 
 
 
 
Esempio n. 14
0
    for k in xrange(0,9):
      if j==0 and k>0:break
      for m in xrange(0,5):       #7
        if (k==0 or j==0) and m>0:break
        for n in xrange(0,7):    #11
          if (k==0 or j==0 or m==0) and n>0:break
          for o in xrange(0,6):   #13
            if (k==0 or j==0 or m==0 or n==0) and o>0:break
            for p in xrange(0,4):  #17
              if (k==0 or j==0 or m==0 or n==0 or o==0) and p>0:break
              for q in xrange(0,3): #19
                if (k==0 or j==0 or m==0 or n==0 or o==0 or p==0) and q>0:break			  
                for r in xrange(0,1):  #23
                  if (k==0 or j==0 or m==0 or n==0 or o==0 or p==0 or q==0) and r>0:break                  
                  N = 2**i * 3**j * 5**k * 7**m * 11**n * 13**o * 17**p * 19** q * 23**r;N1=N+1
                  if N >= 1000000000:continue
                  while True:
                    N1 +=2
                    if miller_rabin(N1):
                       M = N1-N
                       #if M not in d:print i,j,k,m,n,o,p,q,r,":",N,M
                       d[M]=1
                       #print i,j,k,m,n,o,p,q,r,":",N,M
                       break
                       #print i,j,k,m,n,o,p,q,r,":",N
summ=0
for p in d:
  #print p
  summ+=p
print "sum of distinct pseudo-fortunate numbers is", summ		   
print "time elapsed is",time()-st
Esempio n. 15
0
                    f[i] = [p]
                    break

        if p not in f: f[p] = [p]
    return f


st = time()

F = FactorSieve(50000000)
#print F
print time() - st
exit()

summ = 0
x = 20000000
y = 5000000
z = 5000000
for x in xrange(20000000, 15000000, -1):

    if x % z == 0:
        v = x / z
        z -= 1
        summ += sum(RetFact(v))
        continue
    elif miller_rabin(x):
        summ += x
        continue
    else:
        summ += sum(RetFact(x))
Esempio n. 16
0
def check(a, b):
    return euler.miller_rabin(int(a + b)) and euler.miller_rabin(int(b + a))
Esempio n. 17
0
           k *= p
           f[i].append(p)
       if f[p]==[]:f[p]=[p]
  return f
 
from time import time
st = time()
N=1*10**7
print "factoring integers up to ", N
#F=FactorSieve(N) 
print "factor sieve complete and hogging memory..."
ctr = 0
plist=[]
for j in xrange(100000,200000):
  i = j
  if miller_rabin(i):continue
  f = RetFact(i)
  if len(f)==1:continue
  A = isAchilles(f)
  if not A:continue
  phiA = Phi(i,f)
  #fphi=RetFact(phiA)
  fphi=RetFact(phiA)
  B = isAchilles(fphi)
  if not B:continue
  #if A and B and (set(f)==set([2,3]) or set(f)==set([3,2])): print i, f,":",phiA, fphi
  #if A and B and (set(f)==set([2,3])): print i, f,",",f.count(2),f.count(3),":",phiA, fphi
  #if A and B: print i, len(set(f)),":", f ,":",fphi #,",",f.count(2),f.count(3),":",phiA, fphi
  if A and B: print f[-1],"<",i,":", f ,": ",RetFact(f[-1]-1)
  ctr+=1
  plist.append(f[-1])  
Esempio n. 18
0
def main():
    return sum(
        euler.miller_rabin(3 * i * i + 3 * i + 1)
        for i in range(1, int((LIMIT // 3) ** 0.5))
    )
Esempio n. 19
0
        if x < 101:
            l.append(x)

l = sorted(l)
print l

for k in xrange(2, 6):
    c = combinations(l, k)

    for f in c:
        if gcd2(f):
            p = sum(f)

            if p > 100: continue
            print k, f, p
            if miller_rabin(p):
                #print "prime ",f[0],f[1], p
                if p not in d:
                    d[p] = 1
                else:
                    d[p] = d[p] + 1

summ = 0
for p in d:
    if d[p] == 1:
        summ += p
        print p
print summ

print
print d