Java thinks a squared prime over 100k has factor under 30k [duplicate]

13 hours ago 3
ARTICLE AD BOX

I made an intelliJ project in Java 11. I ran the following code:

long bigSquaredPrime = 100151 * 100151; System.out.println(bigSquaredPrime % 50207); System.out.println(bigSquaredPrime % 28687);

Even though 100151 is prime, and therefore bigSquaredPrime should have that as its only factor besides 1 and itself, both of these lines are returning 0. (28,687 and 50,207 are both prime. I chose those specific numbers because a method I wrote for finding prime factors was returning them as the prime factors of 100151 squared.)

Why is this happening? If modulus cannot be trusted when working with big numbers, what is a better way to search for divisibility when checking for prime factors?

Todd R's user avatar

4

Read Entire Article