Memory Error in Python despite 0.5 GB RAM left -


i using sieve of eratosthenes in python program find prime factors. here code -

import time import sys  p=[]  def sieve(n):     p.append(false)   # 0 isn't prime     p.append(false)   # 1 isn't prime     i=2     while (i<=n):         if i%2==0:             p.append(false)        else:             p.append(true)        i+=1     #creating sieve , putting numbers false , odd true     #even numbers can never prime except 2 become true      p[2]=true      sq=int(n**0.5)  #storing square root of n     i=3     while (i<=sq):         k=i*i         while k<=n:             p[k]=false             k+=(2*i)          i+=2  def primefactors(n,x):     print "the prime factors : "     if(n%2==0):         print 2         while(n%2==0):             n/=2     i=3     while(i<len(p)):         if(n==1):             break          if(p[i]):            if(n%i==0):                print                while(n%i==0):                     n/=i         i+=2     if n==x:         print none     elif n!=1:         print n  def main ():     print "enter number factored "     n=raw_input()     n=int(n)     start=time.clock()     sieve(n**0.5+1)     primefactors(n,n)     end=time.clock()     print "seconds : "+str(end-start)  main() 

now, when trying factor 18 digit numbers receiving memory error while creating list. however, windows task manager shows 1.48 gb ram used, while have around 2.2 gb usable ram. reason behind this?

i have added screenshot of task manager when memory error occurred.(cannot post images yet here here link - image)

also, know there other methods factoring primes faster, know why memory error happening before ram totally utilised.

check here

therefore maximum size of python list on 32 bit system 536,870,912 elements.


Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -