[Tutor] large number question

Dick Moores rdm at rcblue.com
Sun Sep 26 06:08:14 CEST 2004


I've written a program that will take a range of integers and tell me 
which are prime, and also tell me the prime factors of the non-primes 
(reinventing the wheel). It works well and efficiently, I believe, but 
I'm wondering if there's a way around the apparent limit on the size of 
integers. If I enter anything larger than about 4,610,000,000,000,000,000 
(4 quintillion, 610 quadrillion in American English), I get
"OverflowError: long int too large to convert to int"

I won't attach my program here, but an obviously important function is
================================
def isPrime(n):
     """returns True if n is prime; False if not"""
     prime = True
     if n < 2:
         prime = False
     else:
         for x in xrange(2,int(n**.5 + 1)):
             if n % x == 0:
                 prime = False
                 break
     return prime
==============================

If I use just isPrime alone, I get the same error message. Where does 
this limit come from? From Python? From Windows XP? From Dell (which made 
my computer)?

Python v2.3.4, Windows XP.

Thanks, tutors.

Dick Moores
rdm at rcblue.com




More information about the Tutor mailing list