title: Handle arbitrarily large numbers in python
body: <p>I'm working through project Euler in order to further my programming skills. I've run into an interesting problem after revisiting my code for problem 3. Here's my code:</p>
  
  <pre><code># prime numbers are only divisible by unity and themselves
  # (1 is not considered a prime number by convention)
  def isprime(n):
      '''check if integer n is a prime'''
      # make sure n is a positive integer
      n = abs(int(n))
      # 0 and 1 are not primes
      if n &lt; 2:
          return False
      # 2 is the only even prime number
      if n == 2: 
          return True    
      # all other even numbers are not primes
      if not n &amp; 1: 
          return False
      # range starts with 3 and only needs to go up the squareroot of n
      # for all odd numbers
      for x in range(3, int(n**0.5)+1, 2):
          if n % x == 0:
              return False
      return True
  
  
  try:
      num = int(input('Please input a natural number:'))
  except ValueError:
      print("Erm.. No. I need a number.")
  
  
  mylist = []
  check = True
  newnum = num
  i= 0
  
  
  if isprime(num):
      print("%r is a prime number."%num)
  
  else:
      while check:
          if isprime(i):
              if newnum % i ==0:
                  mylist.append(i)
                  print("%r is a prime factor of %r"%(i,num))
                  newnum = newnum/i
                  i=0
  
                  if newnum ==1:
                      check = False
  
          if i==num:
              print("I guess the program broke.")
              check = False
          i+=1
  
      print ("The largest prime factor for %r is:"%num)
      print (max(mylist))
      print ("The list of prime factors for %r is:"%num)
      print (mylist)
  </code></pre>
  
  <p>So the problem I ran into is this code will run forever with numbers longer than 17 digits (I suspect anything higher than 144155188075855872 which is 2^59; it works with some 18 digit numbers and not others). </p>
  
  <p>I found that if I input a number higher than that and check the answers with the Windows calculator, the answer will be very close to the whole number but it will have a decimal portion.</p>
  
  <p>How do I change my function to accept and CORRECTLY compute arbitrarily large numbers? (preferably without using nonstandard libraries)</p>
  
  <p>Thanks!</p>