Page 4 of 5
Re: problem 10
Posted: Mon Jun 24, 2013 1:25 pm
by RishadanPort
As a general rule, as Project Euler has stated... All problems can be solved in under 1 minute.
Re: Problem 010
Posted: Mon Jun 24, 2013 7:36 pm
by rayfil
@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.
Re: Problem 010
Posted: Wed Jul 31, 2013 1:44 pm
by bcbarnes
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.
Re: Problem 010
Posted: Mon Nov 25, 2013 7:06 pm
by edenn001
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.
Re: Problem 010
Posted: Sat Jul 26, 2014 3:14 pm
by Anromeda
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 !
Re: Problem 010
Posted: Sat Jul 26, 2014 3:30 pm
by pieppiep
The sum of the primes below 2000 is 277050.
Do you get that same answer?
Re: Problem 010
Posted: Sat Jul 26, 2014 4:12 pm
by Anromeda
pieppiep wrote:The sum of the primes below 2000 is 277050.
Do you get that same answer?
Yes !
for 20000 it is 21171191
for 200000 it is 1709600813
Re: Problem 010
Posted: Sat Jul 26, 2014 4:19 pm
by pieppiep
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.
Re: Problem 010
Posted: Sat Jul 26, 2014 4:45 pm
by pieppiep
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,
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!");
}
}
Re: Problem 010
Posted: Thu Aug 21, 2014 8:25 pm
by Falke88
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?
Re: Problem 010
Posted: Thu Aug 21, 2014 8:31 pm
by pieppiep
A few posts above this one I said result = 277050 for 2000
Help for problem 010
Posted: Sat Sep 06, 2014 3:20 pm
by alexanderameye
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)
Re: Help for problem 010
Posted: Sat Sep 06, 2014 4:48 pm
by nicolas.patrois
Wrong subforum and you may not ask for tips in the right subforum.

Re: Help for problem 010
Posted: Sun Sep 07, 2014 5:26 pm
by Svartskägg
alexanderameye wrote:Now the calculation time to get the first 1000 prime numbers is about 5 seconds,
Basic on a Commodore 64?
Re: Problem 010
Posted: Sun Sep 07, 2014 6:55 pm
by nicolas.patrois
Brute force algorithm?
Re: Help for problem 010
Posted: Sun Sep 07, 2014 8:16 pm
by euler
Svartskägg wrote:Basic on a Commodore 64?
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).
Re: Problem 010
Posted: Sun Sep 07, 2014 10:28 pm
by v6ph1
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...
You should check your implementation and compare it with the description from wikipedia. (example code is there linked, too)
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
Problem 10: Summation of Primes Below Two Million.
Posted: Wed Apr 26, 2017 9:34 pm
by HappyS5
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.
Re: Problem 010
Posted: Thu Apr 27, 2017 2:58 am
by HappyS5
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.
Re: Problem 010
Posted: Wed Jul 24, 2019 1:14 am
by di89resyd
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?