Page 1 of 5

Problem 010

Posted: Fri May 23, 2008 9:58 pm
by yukido
This one's driving me insane.
No matter what I do, it keeps popping up the same number - which should be a good thing - but PE says it's the wrong answer.

I use C(++) and I know for sure that finding the prime numbers cannot possibly be the problem since it's not that hard and I've used the same method as I have for one of the other problems that turned out a-ok.

I just can't figure out the error in my program.
I thought maybe the integer datatype was too small to hold the sum of the primes but then I put unsigned long long and it still kept the same value in the end.

Maybe I just don't understand the problem itself.
Any ideas?

Re: Problem nr. 10

Posted: Fri May 23, 2008 10:08 pm
by daniel.is.fischer
If you get the same value for unsigned long long as for int, unless int is 64 bits on your platform, it definitely is wrong. The result exceeds 232.

Re: Problem nr. 10

Posted: Sat May 24, 2008 1:37 pm
by guana
Some compilers use __int64 data type for 64-bit integers, try using that one.

Re: Problem nr. 10

Posted: Sat May 24, 2008 2:50 pm
by yukido
thanks for the help!

declaring the sum as a long double instead of an int type finally worked.

Re: Problem nr. 10

Posted: Sat May 24, 2008 3:01 pm
by daniel.is.fischer
Odd. 64 bit integers, signed or unsigned, should have no problems. Would you PM me the code, so I can have a look?

Problem 10

Posted: Mon Jun 23, 2008 11:46 pm
by esgt
Solved problem 10 tonight. My solution was accepted. Then looking at the algorithms by others I note they agree on a different answer. e.g.
NB. R E Boss' solution? December 04
NB. A Java solution by Stefan_yes gets the same solution
NB. Roger Hui's solutions? June 05

Has Problem 10 changed?

Re: Problem 10

Posted: Mon Jun 23, 2008 11:58 pm
by daniel.is.fischer
Yes, problem 10 is one of a few which have been changed, formerly the limit was one million.

Problem 10

Posted: Wed Sep 24, 2008 12:20 pm
by DTox2k
Hello everybody,

i have a little problem with problem 10. I tried to solve it in 2 different ways with Java, first by simply searching each prime below 2000000 and then with the sieve of Eratosthenes. Both ways i get the same result but it still seems to be wrong and i don't find the mistake.
Maybe somebody could check my code and my result (i would send it by PM if somebody would agree to do it :) ) and give me a hint what's wrong.
Thanks for your help and sorry for all the mistakes a probably did ;-) .

Cheers!
DTox2k

Problem 10 (View Problem)

Re: Problem 10

Posted: Wed Sep 24, 2008 12:46 pm
by hk
Be careful: the sum exceeds 32bit integer range.
If that is not the problem you can PM me.

Re: Problem 10

Posted: Wed Sep 24, 2008 12:51 pm
by DTox2k
that was the problem...so easy and i didn't find it :o
Thank you very much :) !!!

Re: Problem 10

Posted: Wed Sep 24, 2008 1:46 pm
by hk
You are welcome.
It is a known issue for this problem (and many higher ones)

Re: Problem nr. 10

Posted: Wed Oct 22, 2008 7:09 am
by MaJJ
Bah, this problem's first one in which I had to use specialized programs :) But the solution was SO FAST! :D

Expand

Expand

Worked great ... But now I'll have no peace until I'll write the code myself!

Edit:
Yay, finally did it (in PHP)... C-compiled program always crashed when calculating 2 000 000 as a maximum (but at lower numbers it was OK) ... PHP rulez :D

problem 010

Posted: Tue Jul 27, 2010 2:43 pm
by mrnitro30103
hello,
I did the sum of all prime below 2millions, but it keeps saying it's wrong.
but I check it for any lower values, like 10, 30, 70, and it's fine (checking against pre-calculated primes table). Also I checked the difference between
the sum before 2 million and the one after, and the difference is a real existing prime . I dont really understand why for low values it's correct and it seems also for the higher ones. I'm using C.

thanks
mrn

Re: problem 010

Posted: Tue Jul 27, 2010 2:52 pm
by mrnitro30103
some values I get :

n = 10 , s = 17
n = 30 , s = 129
n = 100, s = 1060
n = 1000, s= 78627

n= 10000, s= 5772214

Re: problem 010

Posted: Tue Jul 27, 2010 2:53 pm
by hk
Please don't start a new topic for a problem when there exists one allready for it.
How many digits does your answer have?

Re: problem 010

Posted: Tue Jul 27, 2010 3:07 pm
by mrnitro30103
hello,
10 , but I ran the same code in java, and it gave correct answer, 12 digits.
I guess it's some conversion/cast/overflow? any insights? thanks!


mrn

Re: problem 010

Posted: Tue Jul 27, 2010 3:09 pm
by mrnitro30103
I didnt see any problem 010 topics?., my fault

Re: problem 010

Posted: Tue Jul 27, 2010 3:10 pm
by hk
The answer exceeds 32 bit integer range.
The variable in which you are summing should be a 64 bit integer.

Re: problem 010

Posted: Mon Jan 31, 2011 11:50 am
by kapman
The link to the solution discussion for Problem 10 is somehow outdated. The topic is closed and the latest entry is from 2008. It also seems to tackle only the 1000000-question.

Is there a new thread to see solutions for the 2000000 problem? I'm interested in what running times others have on todays computers with the greater number of primes ;)

Re: problem 010

Posted: Tue Feb 01, 2011 4:13 am
by rayfil
For your info, my algo runs in 12 ms on a 2-year-old CoreDuo 1.9GHz for the 2000000 limit. My timing is 6 ms for the 1000000 limit (on the same computer).