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.
- RishadanPort
- Posts: 79
- Joined: Mon Jun 10, 2013 7:31 am
Re: problem 10
As a general rule, as Project Euler has stated... All problems can be solved in under 1 minute.

Rishada is the gateway to free trade—but the key will cost you.
- rayfil
- Administrator
- Posts: 1412
- Joined: Sun Mar 26, 2006 5:30 am
- Location: Quebec, Canada
- Contact:
Re: Problem 010
@avantika
We realize you are new to this forum. Problem numbers under 100 are padded with leading 0s to make them 3-digit numbers. You will find it easier in the future to find the proper topic.
We realize you are new to this forum. Problem numbers under 100 are padded with leading 0s to make them 3-digit numbers. You will find it easier in the future to find the proper topic.
When you assume something, you risk being wrong half the time.
- bcbarnes
- Posts: 1
- Joined: Wed Jul 31, 2013 2:33 am
- Location: Austin, Texas. USA.
Re: Problem 010
Ok, just thought I'd raise my hand and admit to falling for the 32-bit integer limit trap. I'm somewhat embarrassed, as I've been working with hardware/software for too many years to fall for this...
Anyway, thought I'd share as I just started doing the Euler problems.
Anyway, thought I'd share as I just started doing the Euler problems.
-
edenn001
- Posts: 1
- Joined: Mon Nov 25, 2013 7:01 pm
Re: Problem 010
just to reiterate what was mentioned in topic, make sure you are using long or double rather than int for the sum. In Java if you use int it wont break and it will give you a wrong answer. I was breaking my head as my code worked perfectly for low numbers, and when I did a count of all the primes below 2 million and compared to what Wolfram alpha had, they matched exactly.
-
Anromeda
- Posts: 2
- Joined: Sat Jul 26, 2014 3:03 pm
Re: Problem 010
I looked for the 32-bit trap
. I am using a 64-bit variable to store the sum
, but still getting a wrong answer
. My count of primes till 2000000 and sum for smaller numbers are however correct.
P.S I used long long to store the sum which i know is of 64-bit. Please help !
P.S I used long long to store the sum which i know is of 64-bit. Please help !
-
pieppiep
- Posts: 23
- Joined: Thu Dec 30, 2010 6:23 am
-
Anromeda
- Posts: 2
- Joined: Sat Jul 26, 2014 3:03 pm
Re: Problem 010
Yes !pieppiep wrote:The sum of the primes below 2000 is 277050.
Do you get that same answer?
for 20000 it is 21171191
for 200000 it is 1709600813
-
pieppiep
- Posts: 23
- Joined: Thu Dec 30, 2010 6:23 am
Re: Problem 010
Yeah, I got the same for those.
Can you pm me you answer for 2000000, may I can see what you're doing wrong if I compare it with the correct one.
Can you pm me you answer for 2000000, may I can see what you're doing wrong if I compare it with the correct one.

-
pieppiep
- Posts: 23
- Joined: Thu Dec 30, 2010 6:23 am
Re: Problem 010
myAnswer mod (2^32) = yourAnswer
You say you are using a 64-bit variable to store the sum, but are you also adding 64-bit values?
Maybe you can try something like,
You say you are using a 64-bit variable to store the sum, but are you also adding 64-bit values?
Maybe you can try something like,
Code: Select all
long long total = 0;
long long newTotal;
DoStuff();
start your loop for adding here
{
newTotal = total + nextPrime;
if (newTotal < total)
{
Console.WriteLine("There is an error in the code here!");
}
}

-
Falke88
- Posts: 2
- Joined: Sun Aug 03, 2014 1:29 pm
Re: Problem 010
Hey guys...
My result is a 12 digit number...sadly the wrong one kinda...
I tested values until 500 and compared it with a pre-calculated prime table. Every number is equal to the ones in that list.
Surely there always can be some issue in the ascending numbers but I can't figure out what it might be...
I ulong all integer vars so there can't be the problem.
ie.
result = 458860 for number = 2000
can anybody validate that?
My result is a 12 digit number...sadly the wrong one kinda...
I tested values until 500 and compared it with a pre-calculated prime table. Every number is equal to the ones in that list.
Surely there always can be some issue in the ascending numbers but I can't figure out what it might be...
I ulong all integer vars so there can't be the problem.
ie.
result = 458860 for number = 2000
can anybody validate that?
-
pieppiep
- Posts: 23
- Joined: Thu Dec 30, 2010 6:23 am
-
alexanderameye
- Posts: 1
- Joined: Sat Sep 06, 2014 3:14 pm
Help for problem 010
I have written a program to find all the prime numbers <2000000, and the program is based on the sieve of Eratosthenes Link: http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes Now the calculation time to get the first 1000 prime numbers is about 5 seconds, but if I set it to 2 million, it takes like forever. Is there any way I could optimize the speeds?
I could post some code under here, or the exact way it works, but idk if this is allowed...
Thank you anyways!!
(Merged with existing topic by moderator)
I could post some code under here, or the exact way it works, but idk if this is allowed...
Thank you anyways!!
(Merged with existing topic by moderator)
- nicolas.patrois
- Posts: 118
- Joined: Fri Jul 26, 2013 4:54 pm
- Contact:
-
Svartskägg
- Posts: 55
- Joined: Thu Mar 29, 2012 12:55 pm
- Location: Sweden
Re: Help for problem 010
Basic on a Commodore 64?alexanderameye wrote:Now the calculation time to get the first 1000 prime numbers is about 5 seconds,

320641_5486fc18ea1dcc4e9a8f29c7677a5c19 <-- my friend key
- nicolas.patrois
- Posts: 118
- Joined: Fri Jul 26, 2013 4:54 pm
- Contact:
- euler
- Administrator
- Posts: 5095
- Joined: Sun Mar 05, 2006 4:49 pm
- Location: Cheshire, England
- Contact:
Re: Help for problem 010
Now you're either showing your age or you are lucky enough to have an older relative who remembers the "good old days" (a.k.a. the stone age of computing).Svartskägg wrote:Basic on a Commodore 64?

impudens simia et macrologus profundus fabulae
-
v6ph1
- Posts: 134
- Joined: Mon Aug 25, 2014 7:14 pm
Re: Problem 010
You should check your implementation and compare it with the description from wikipedia. (example code is there linked, too)alexanderameye wrote:I have written a program to find all the prime numbers <2000000, and the program is based on the sieve of Eratosthenes Link: http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes Now the calculation time to get the first 1000 prime numbers is about 5 seconds, but if I set it to 2 million, it takes like forever. Is there any way I could optimize the speeds?I could post some code under here, or the exact way it works, but idk if this is allowed...
The computation time for 1000 should be a lot less than 1s. - The complexity is linear: so until 2000 your time should double.
For more optimization, you may use a profiling tool.
best regards

- HappyS5
- Posts: 11
- Joined: Wed Apr 26, 2017 9:17 pm
Problem 10: Summation of Primes Below Two Million.
Hello,
I am new to programming, as I said, and I figured out that I am the one that made the error. I am sorry to have second guessed your team. I was making a very basic error. I hope all are well.
I really enjoy the problems I have faced so far. I got the first 10 correct, consecutively, and that is a major advancement on my end because I am learning c++ programming and I am not a mathematician.
Rather, I am a medically retired chemical engineer who also has a degree in biological sciences. I have 1991 Gulf War Illness and it caused me, along with the stress from employment as a chemical engineer in the pharmaceutical industry, to develop schizoaffective disorder (bipolar type). As such, I am a 100% total and permanent disabled veteran via the Veterans Affairs. I also have combat PTSD.
Anyhow, all my checks were working out but I was getting the wrong summation and "accumulation" so I wondered if the problem's answer had been corrupted or something. In truth, I was making a very basic error. Sorry to have second guessed you all. I found the error because I also knew that I am new to programming and there are so many areas where a newbie can make errors. So, I kept trying. I finally figured it out.
As mentioned, I solved 10 problems in a row so I look forward to the badge.
To me, these problems have been difficult.
I am new to programming, as I said, and I figured out that I am the one that made the error. I am sorry to have second guessed your team. I was making a very basic error. I hope all are well.
I really enjoy the problems I have faced so far. I got the first 10 correct, consecutively, and that is a major advancement on my end because I am learning c++ programming and I am not a mathematician.
Rather, I am a medically retired chemical engineer who also has a degree in biological sciences. I have 1991 Gulf War Illness and it caused me, along with the stress from employment as a chemical engineer in the pharmaceutical industry, to develop schizoaffective disorder (bipolar type). As such, I am a 100% total and permanent disabled veteran via the Veterans Affairs. I also have combat PTSD.
Anyhow, all my checks were working out but I was getting the wrong summation and "accumulation" so I wondered if the problem's answer had been corrupted or something. In truth, I was making a very basic error. Sorry to have second guessed you all. I found the error because I also knew that I am new to programming and there are so many areas where a newbie can make errors. So, I kept trying. I finally figured it out.
As mentioned, I solved 10 problems in a row so I look forward to the badge.
HappyS5
Chris
Chris
- HappyS5
- Posts: 11
- Joined: Wed Apr 26, 2017 9:17 pm
Re: Problem 010
Hello,
I am sure we are not supposed to give answers. With that said, I want everyone to know that I, as a new C++ programmer and the only language I have studied, finally figured out the problem with my code. I kept getting the same answer too, and all my checks, like size of finished vector, matched what I found on the Internet, and the answer to my incompetence was posted here to assist another. I had figured mine out already though. Still, I did as has been suggested here and it is a VERY basic programming concept. It also makes an amazing difference in the number output.
As a side note, though, my use of vector accumulate still gave me the wrong answer.
I am sure we are not supposed to give answers. With that said, I want everyone to know that I, as a new C++ programmer and the only language I have studied, finally figured out the problem with my code. I kept getting the same answer too, and all my checks, like size of finished vector, matched what I found on the Internet, and the answer to my incompetence was posted here to assist another. I had figured mine out already though. Still, I did as has been suggested here and it is a VERY basic programming concept. It also makes an amazing difference in the number output.
As a side note, though, my use of vector accumulate still gave me the wrong answer.
HappyS5
Chris
Chris
-
di89resyd
- Posts: 1
- Joined: Wed Jul 24, 2019 1:09 am
Re: Problem 010
I don't know any tricks about primes. My brute force solution to this problem takes too long (i'm using C). Is it "cheating" to look up the Sieve method on wikipedia? I've heard the name but I don't know what it is. Or should we ideally be figuring the trick out from scratch?
