Integers Come in All Sizes

I received an email message with a HackerRank challenge. If interested the simple challenge is located at the following URL:

The challenge is quite simple when using Python. Since Python 3 the distinction between integers, long integers and unlimited size integers is gone. In Python 3 an integer could probably take all the virtual memory in your machine ;o).

The challenge is to compute and display the integer results for a computation that could easily produce results larger than a long integer in C or C++ (i.e., 2 ** 64).

The test case using Python on the console of the Spyder 3 IDE follows:






The Python code follows:

# **** input parameters ****

a = int(input())

b = int(input())

c = int(input())

d = int(input())

# **** display values ****

#print(“a:”, a, “b:”, b, “c:”, c, “d:”, d)

# **** compute and display result ****

print(pow(a, b) + pow(c, d))

The solution passed the two test cases.

If you have comments or questions regarding this or any other post in this blog please do not hesitate and send me a message. Will respond as soon as possible and will not mention your name unless you explicitly tell me to do so.


Follow me on Twitter: @john_canessa

Leave a Reply

Your email address will not be published. Required fields are marked *