Often big numbers become negative

This image shows what you’re looking for. In your case it’s obviously larger numbers, but the principle stays the same.

Examples of limits in java are:
int: −2,147,483,648 to 2,147,483,647.
long: -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807

In the image 0000, 0001 etc, shows the binary representation of the numbers.

Image explaining two's complement

EDIT: In project euler you often have to think of a way to work around the lagre numbers. The problems are designed with numbers that big so that you can’t use the ordinary way of problem solving. However, if you find that you really need to use them, i suggest studying BigInteger anyway. You will find it useful in the long run, and it’s not all that complicated. Here is a link with lots of understandable examples:
BigInteger Example

Leave a Comment