Problem 010
Forum rules
As your posts will be visible to the general public you are requested to be thoughtful in not posting anything that might explicitly give away how to solve a particular problem.
This forum is NOT meant to discuss solution methods for a problem.
See also the topics:
Don't post any spoilers
Comments, questions and clarifications about PE problems.
As your posts will be visible to the general public you are requested to be thoughtful in not posting anything that might explicitly give away how to solve a particular problem.
This forum is NOT meant to discuss solution methods for a problem.
In particular don't post any code fragments or results.
Don't start begging others to give partial answers to problems
Don't ask for hints how to solve a problem
Don't start a new topic for a problem if there already exists one
Don't start begging others to give partial answers to problems
Don't ask for hints how to solve a problem
Don't start a new topic for a problem if there already exists one
See also the topics:
Don't post any spoilers
Comments, questions and clarifications about PE problems.
-
yukido
- Posts: 2
- Joined: Fri May 23, 2008 9:44 pm
Problem 010
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?
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?
- daniel.is.fischer
- Posts: 2400
- Joined: Sun Sep 02, 2007 11:15 pm
- Location: Bremen, Germany
Re: Problem nr. 10
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.
Il faut respecter la montagne -- c'est pourquoi les gypaètes sont là.
-
guana
- Posts: 10
- Joined: Mon Mar 17, 2008 3:31 pm
-
yukido
- Posts: 2
- Joined: Fri May 23, 2008 9:44 pm
Re: Problem nr. 10
thanks for the help!
declaring the sum as a long double instead of an int type finally worked.
declaring the sum as a long double instead of an int type finally worked.
- daniel.is.fischer
- Posts: 2400
- Joined: Sun Sep 02, 2007 11:15 pm
- Location: Bremen, Germany
Re: Problem nr. 10
Odd. 64 bit integers, signed or unsigned, should have no problems. Would you PM me the code, so I can have a look?
Il faut respecter la montagne -- c'est pourquoi les gypaètes sont là.
-
esgt
- Posts: 1
- Joined: Mon Jun 23, 2008 11:36 pm
- Location: Derbyshire
Problem 10
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?
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?
- daniel.is.fischer
- Posts: 2400
- Joined: Sun Sep 02, 2007 11:15 pm
- Location: Bremen, Germany
Re: Problem 10
Yes, problem 10 is one of a few which have been changed, formerly the limit was one million.
Il faut respecter la montagne -- c'est pourquoi les gypaètes sont là.
-
DTox2k
- Posts: 2
- Joined: Mon Sep 22, 2008 10:34 am
Problem 10
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)
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
Thanks for your help and sorry for all the mistakes a probably did
Cheers!
DTox2k
Problem 10 (View Problem)
- hk
- Administrator
- Posts: 12832
- Joined: Sun Mar 26, 2006 10:34 am
- Location: Haren, Netherlands
Re: Problem 10
Be careful: the sum exceeds 32bit integer range.
If that is not the problem you can PM me.
If that is not the problem you can PM me.

War ruins the life and health of untold numbers of innocent children.
-
DTox2k
- Posts: 2
- Joined: Mon Sep 22, 2008 10:34 am
- hk
- Administrator
- Posts: 12832
- Joined: Sun Mar 26, 2006 10:34 am
- Location: Haren, Netherlands
Re: Problem 10
You are welcome.
It is a known issue for this problem (and many higher ones)
It is a known issue for this problem (and many higher ones)

War ruins the life and health of untold numbers of innocent children.
-
MaJJ
- Posts: 49
- Joined: Tue Oct 14, 2008 12:14 am
Re: Problem nr. 10
Bah, this problem's first one in which I had to use specialized programs
But the solution was SO FAST! 
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
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


-
mrnitro30103
- Posts: 4
- Joined: Tue Jul 27, 2010 2:37 pm
problem 010
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
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
-
mrnitro30103
- Posts: 4
- Joined: Tue Jul 27, 2010 2:37 pm
Re: problem 010
some values I get :
n = 10 , s = 17
n = 30 , s = 129
n = 100, s = 1060
n = 1000, s= 78627
n= 10000, s= 5772214
n = 10 , s = 17
n = 30 , s = 129
n = 100, s = 1060
n = 1000, s= 78627
n= 10000, s= 5772214
- hk
- Administrator
- Posts: 12832
- Joined: Sun Mar 26, 2006 10:34 am
- Location: Haren, Netherlands
Re: problem 010
Please don't start a new topic for a problem when there exists one allready for it.
How many digits does your answer have?
How many digits does your answer have?

War ruins the life and health of untold numbers of innocent children.
-
mrnitro30103
- Posts: 4
- Joined: Tue Jul 27, 2010 2:37 pm
Re: problem 010
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
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
-
mrnitro30103
- Posts: 4
- Joined: Tue Jul 27, 2010 2:37 pm
- hk
- Administrator
- Posts: 12832
- Joined: Sun Mar 26, 2006 10:34 am
- Location: Haren, Netherlands
Re: problem 010
The answer exceeds 32 bit integer range.
The variable in which you are summing should be a 64 bit integer.
The variable in which you are summing should be a 64 bit integer.

War ruins the life and health of untold numbers of innocent children.
-
kapman
- Posts: 2
- Joined: Mon Jan 31, 2011 11:45 am
Re: problem 010
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
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

- rayfil
- Administrator
- Posts: 1412
- Joined: Sun Mar 26, 2006 5:30 am
- Location: Quebec, Canada
- Contact:
Re: problem 010
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).
When you assume something, you risk being wrong half the time.