Jump to content
Science Forums

Deficient & Abundant Number Fun


Turtle

Recommended Posts

i'm so proud of my code i think i'll post it here.

def total(A,n):
   v = 1
   total = 1
   t = 1
   for i in range(0,len(A)-1):
      if A[i] == A[i+1]:
         v*=A[i]
         t += v
      else:
         v*=A[i]
         t += v
         total *= t
         v = 1
         t = 1
   v*=A[-1]
   t += v
   total *= t
   total -= n
   return total

primes = [False,False,True,True]+[False,True,False,True,False,False]*16667
n = 5
while n*n < len(primes):
   x = len(primes)/n
   while x > 1:
      if primes[x]:
         primes[x*n] = False
      x -= 1
   n += 1
   while not primes[n]:
      n += 1

t = 2000000001
for i in range(0,10000):
   factor = [1]*1000000
   j = 2
   while j < len(primes):
      v = t%j
      k = t-v+j
      while k < t+1000000:
         s = k

         if factor[k-t] == 1:
            factor[k-t] = [j]
            s /= j
         while s%j == 0:
            factor[k-t] += [j]
            s /= j
         k += j
      j += 1
      while  j < len(primes) and not primes[j]:
         j += 1
   for j in range(0,1000000):
      if factor[j] != 1:
         if j +t == 18:
            print factor[j]
         r = total(factor[j],j+t)
         if r == j+t+3:
            print r
   t += 1000000
   print t
Edited by phillip1882
Link to comment
Share on other sites

ah poo, just realized there's a big ol' flaw in my code. i knew it was too good to be true. let me rehash it.

edit: fixed.

def total(A,n):
   v = 1
   total = 1
   t = 1
   for i in range(0,len(A)-1):
      if A[i] == A[i+1]:
         v*=A[i]
         t += v
      else:
         v*=A[i]
         t += v
         total *= t
         v = 1
         t = 1
   v*=A[-1]
   t += v
   total *= t
   total -= n
   return total

primes = [False,False,True,True]+[False,True,False,True,False,False]*16667
n = 5
while n*n < len(primes):
   x = len(primes)/n
   while x > 1:
      if primes[x]:
         primes[x*n] = False
      x -= 1
   n += 1
   while not primes[n]:
      n += 1

t = 2000000001
for i in range(0,10000):
   factor = [1]*1000000
   j = 2
   while j < len(primes):
      v = t%j
      k = t-v+j
      while k < t+1000000:
         s = k

         if factor[k-t] == 1:
            factor[k-t] = [j]
            s /= j
         while s%j == 0:
            factor[k-t] += [j]
            s /= j
         k += j
      j += 1
      while  j < len(primes) and not primes[j]:
         j += 1
   for j in range(0,1000000):
      if factor[j] != 1:
         m = j+t
         for q in range(0,len(factor[j])):
             m /= factor[j][q]
         if m != 1:
            factor[j] += [m]
         if j +t == 2500000020:
            print factor[j]
         r = total(factor[j],j+t)
         if r == j+t+3:
            print r
   t += 1000000
   print t
Edited by phillip1882
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...