The first known prime found to exceed one million digits was discovered in 1999, and is a Mersenne prime of the form 2^6972593−1; it contains exactly 2,098,960 digits. Subsequently other Mersenne primes, of the form 2^p−1, have been found which contain more digits.

However, in 2004 there was found a massive non-Mersenne prime which contains 2,357,207 digits: 28433�2^7830457+1.

Find the last ten digits of this prime number.

I tried using BigInteger to compute the prime it self, I think it would take years to compute it, so I need another way around it. Can anyone suggest any method?

thanks

then add the one, giving me 25.

[ May 15, 2008: Message edited by: fred rosenberger ]

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors

Heck, I think i could even get clever and when the 10's digit is greater than 4, i can pretty much ignore it and just double the 1's digit... i THINK.

this may not give me a performance boost (i think it would actually slow things down), but it is interesting...

[edit]nevermind... that's not correct.[/edit]

in your case, you'd have to account for the 10 digits, but that's going to process much faster than the hundreds or thousands of digits.

[ May 15, 2008: Message edited by: fred rosenberger ]

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors

help us help you.

ok... i played with it a little. i made your for loop only go 5 times. and, i did this:

see if you can figure out the problem from here...

[ May 15, 2008: Message edited by: fred rosenberger ]

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors

another note... you really don't even need BigInteger for this. I think i have a solution that is 22 lines, uses only longs and ints. My answer is

8739992577

and my program runs in under a second.

[ May 15, 2008: Message edited by: fred rosenberger ]

java -cp . Problem97

n is 2

n.pow is 1

n is 4

n.pow is 2

n is 16

n.pow is 3

n is 256

n.pow is 4

n is 65536

n.pow is 5

n is 4294967296

n.pow is 6

n is 13709551614

n.pow is 7

n is 13709551614

n.pow is 8

9223372036854775807

What you are doing here each time is raising N to the power of 2. So, first you take 2, and raise it to the power of 2, giving 4.

you then take 4, and raise IT to the power of 2, giving you 16. you then raise 16 to the power of 2, giving 256, etc.

you don't want to raise it by the power of 2 each iteration through the loop... you want to MULTIPLY it by 2 each time through the loop.

Also, there is a much simpler way to chop of extra digits, using a basic operator. do you know what 'modulus' means? It basically means "give me the remainder after i divide". so, '23 mod 5' would be 3. '15 mod 7' would be 1.

so, '217 mod 100' is 17. there is an operator that will do this for you.

[ May 16, 2008: Message edited by: fred rosenberger ]

Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |