-1

I got an hexadecimal

number = C847923CE24DE8B7CA66AB9620BAF1831FE65EA0D9A2928D6D75B12C567F6C2586ED07AE0EE5C8ECD8793F1683AF1893C0BE521A10F69E6DC951DC7E2CB47E8B  

It should be equal to

10489492484628552513045989867681469503774243086255660470449316956846449417667713853937696810038768145686753348376338135274255531844743941964455973060116107

I tried this https://www.programiz.com/python-programming/online-compiler/?ref=374cc95b

But got this error:

Traceback (most recent call last): File "", line 4, in OverflowError: range() result has too many items

dcg
  • 4,187
  • 1
  • 18
  • 32
eoffer
  • 21
  • 2
  • 2
    You need to show us the code that is giving the error, and the link you provide doesn't show it. Please include the code with the problem *in your question* as text, not a link (even if it works) and not a picture (because we can't run it). As your question stands, you are asking us to imagine what you have written and then find the problem in it. – BoarGules Mar 26 '20 at 19:47
  • There are modules that do prime numbers. This is a job for pip. If you're just asking about the hex number, https://stackoverflow.com/questions/209513/convert-hex-string-to-int-in-python – Kenny Ostrom Mar 26 '20 at 19:49
  • 1
    The error message you report (*range result has too many items*) indicates that you are running Python 2. At this stage you should not be investing effort in learning Python 2. – BoarGules Mar 26 '20 at 19:57

2 Answers2

4

If you are ok using a library to check whether the number is prime or not (and your questions isn't about how to write an efficient prime-checker on your own), what about the following:

>>> import sympy
>>> num = int('C847923CE24DE8B7CA66AB9620BAF1831FE65EA0D9A2928D6D75B12C567F6C2586ED07AE0EE5C8ECD8793F1683AF1893C0BE521A10F69E6DC951DC7E2CB47E8B', 16)
# 10489492484628552513045989867681469503774243086255660470449316956846449417667713853937696810038768145686753348376338135274255531844743941964455973060116107L
>>> sympy.isprime(num)
# False

Regarding converting a hex number to a normal (base ten) number, you can do:

>>> int('A', 16)
10

Where the second arg is the base of the input number.

David542
  • 104,438
  • 178
  • 489
  • 842
  • Thanks David542, using a library can work out , pip3 install sympy. – eoffer Mar 27 '20 at 05:06
  • Python also have a math library to factor out this large number ? – eoffer Mar 27 '20 at 05:19
  • @eoffer yea...if you look hard enough you can pretty much find anything. Three good math libraries are https://www.sympy.org/en/index.html, https://numpy.org/, and Scipy. – David542 Mar 27 '20 at 17:01
1

But I also need an efficient prime-checker of my code: why below code can not ihandle large numbers ?

# Program to check if a number is prime or not

num = 407

# To take input from the user
#num = int(input("Enter a number: "))

# prime numbers are greater than 1
if num > 1:
# check for factors
for i in range(2,num):
   if (num % i) == 0:
       print(num,"is not a prime number")
       print(i,"times",num//i,"is",num)
       break
  else:
   print(num,"is a prime number")

  # if input number is less than
  # or equal to 1, it is not prime
  else:
     print(num,"is not a prime number")
eoffer
  • 21
  • 2