Problem 050
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.
Re: Project 50
Thanks everyone. I get it now.
Re: Problem 050
@ apdwyer51
For you information, questions related to specific problems should be posted to the existing topic related to such problem (if one already exists obviously ). Those topics have "Problem XXX" as their subject, where XXX is the problem number padded in front with 0's if needed to have three digits. Your posts have thus been merged into the related topic.
In the future, if you search for the proper topic, you may then find answers to your question(s) without the need to post them.
Hope you are enjoying Project Euler and this forum.
For you information, questions related to specific problems should be posted to the existing topic related to such problem (if one already exists obviously ). Those topics have "Problem XXX" as their subject, where XXX is the problem number padded in front with 0's if needed to have three digits. Your posts have thus been merged into the related topic.
In the future, if you search for the proper topic, you may then find answers to your question(s) without the need to post them.
Hope you are enjoying Project Euler and this forum.
When you assume something, you risk being wrong half the time.

 Posts: 2
 Joined: Fri Jan 27, 2012 11:40 am
Re: Problem 050
Hi, can somebody tell me, how many consecutive primes I have to use, I found solution with 539 consecutives primes but it is wrong.
Re: Problem 050
That's too short.
Re: Problem 050
Recently I revisited this problem, with the sole purpose of optimizing my code, to my surprise I found a post in the problem thread which asserts solutions to larger instances of the problem....some of which are contradictory to the results I have obtained for higher values......I would be obliged if some members, who have solved the problem, could confirm values of 10^7, 10^8 & 10^9 either on the problem thread or through PM.
"When in doubt, use brute force"  Ken Thompson.
Re: Problem 050
It took me some time to find out which post you're possibly refering to reading the thread from page 1 to page 5.
Is it Francky's post on page 5?
Or another post on one of the following pages?
Is it Francky's post on page 5?
Or another post on one of the following pages?
Re: Problem 050
Hi, thanks to pay attention to my code and/or results.
Edit : spoil deleted
You can PM me your results if you want.
Edit : spoil deleted
You can PM me your results if you want.
Last edited by Francky on Sun Sep 16, 2012 12:37 pm, edited 1 time in total.
Entia non sunt multiplicanda praeter necessitatem
Re: Problem 050
Sorry for the late response.....but guess what.....I dug deeper.....although we got different results, looks like we both are correct (as far as the problem statement is concerned) because, for certain larger instances of the problem the answer is not unique......my old code provides only the lower value & it seems your code provides only the higher value......my new code provides both.
"When in doubt, use brute force"  Ken Thompson.
Re: Problem 050
You're right, my code answer the highest prime that is the longest sum of consecutive primes under limit.peedyoJ wrote:Sorry for the late response.....but guess what.....I dug deeper.....although we got different results, looks like we both are correct (as far as the problem statement is concerned) because, for certain larger instances of the problem the answer is not unique......my old code provides only the lower value & it seems your code provides only the higher value......my new code provides both.
I think I can modify it in order to answer other primes with same length for the sum.
Thanks for pointing that and confront our results. It gave an instructive issue.
Edit : done, it was for 10⁷ and 10¹⁵, isn't it ?
597 and 191 for 10⁷, and
469 and 119 for 10¹⁵.
Entia non sunt multiplicanda praeter necessitatem
Re: Problem 050
"The longest sum of consecutive primes below onethousand that adds to a prime, contains 21 terms, and is equal to 953."
Should be "The longest sum of consecutive primes that adds to a prime below 1000..." shouldn't it?
because "The longest sum of consecutive primes below onethousand that adds to a prime", adds to a prime well above 1000.
Should be "The longest sum of consecutive primes that adds to a prime below 1000..." shouldn't it?
because "The longest sum of consecutive primes below onethousand that adds to a prime", adds to a prime well above 1000.
Re: Problem 050
I only made a list of the primes below 47620 because the problem gives a sum with 21 primes. Therefore a list of consecutive primes higher than 47620 can not be longer than 21 (while staying under 1.000.000).
I get the correct solution, but was curious what you guys think. I use a rather old laptop and the performance ist way better when the code doesn't have to find all primes below 1M.
I get the correct solution, but was curious what you guys think. I use a rather old laptop and the performance ist way better when the code doesn't have to find all primes below 1M.
Re: Problem 050
First of all, the 21 terms in the sequence belongs to the largest prime below 1000. I'm almost sure, the longest sum contains more terms than 21, if the limit is 1 million.
Nevertheless your upper limit is wrong, and I want to illustrate on an example. If the limit was 100 and you would have been allowed to use three primes, the upper limit is not 100/3=33. Take the 3 primes to be 29+31+37=97. The largest one among those is bigger than 33.
Nevertheless your upper limit is wrong, and I want to illustrate on an example. If the limit was 100 and you would have been allowed to use three primes, the upper limit is not 100/3=33. Take the 3 primes to be 29+31+37=97. The largest one among those is bigger than 33.
Re: Problem 050
Ah, I see your point. I took it as granted, that the sum will be longer than 21 (it is ), and choose the upper limit for my prime list.
So how about doubling the limit, making it roughly 100.000. That should work and the primes still can be found faster.
So how about doubling the limit, making it roughly 100.000. That should work and the primes still can be found faster.
Re: Problem 050
That was years ago when I solved this problem. Of course the longest chain will be at least 21 long. Since there are a lot of primes, you don't have to double your limit, just raise by 1000, or so, since their average has to be around 1000000/21, if the series cointains 21 terms.
Anyway, for later problems you have to develop some method for testing/collecting primes, to 10 or 100 million, so keep on thinking how to do that.
Anyway, for later problems you have to develop some method for testing/collecting primes, to 10 or 100 million, so keep on thinking how to do that.
Re: Problem 050
Thank you very much for your input! I'm new at programming (due to the fact that I'm 38 years old I consider myself as a latebloomer ) and l'm really glad to get input from seasoned prosTheEvil wrote:That was years ago when I solved this problem. Of course the longest chain will be at least 21 long. Since there are a lot of primes, you don't have to double your limit, just raise by 1000, or so, since their average has to be around 1000000/21, if the series cointains 21 terms.
Anyway, for later problems you have to develop some method for testing/collecting primes, to 10 or 100 million, so keep on thinking how to do that.

 Posts: 1
 Joined: Sun Apr 13, 2014 10:06 pm
Re: Problem 050
I admit to being confused about the language of the problem statement. For the under 1000 section, I got a list of consecutive primes that is 25 long and sums to 281. How can 21 be considered greater than 25?
Re: Problem 050
If you had indeed found such a list of primes, it would have contradicted the problem statement, because 25 is greater than 21.
However, it is definitely impossible that you have done so, because the smallest 25 prime numbers (ranging from 2 up to 97) add to a lot more than 281.
However, it is definitely impossible that you have done so, because the smallest 25 prime numbers (ranging from 2 up to 97) add to a lot more than 281.
Re: Problem 050
Hi everybody. I hope you will not mind, but I wanted to benchmark my solution in C++11. Here are my parameters:
Compiler: GCC 4.7.2
CPU: Intel Core i73517U, 1.90GHz
Flags used in compilation:
Wall Wextra (no output generated)
g (for debugging purpose, Valgrind returned no problems or leaks)
Ofast (slight improvement over O2 and O3)
march and mtune for corei7avx
std=gnu++11 (for vector and algorithm support)
lm
Average runtime is 26.988 seconds. Code returns correct results provided in problem statement and returns correct solution to problem itself. It is not tragic, but regardless one of my slower programs. What bothers me is the fact my solution in C11 (that I feel more proficient with) is only about 25 seconds faster. I'm sensing a lot there is to improve but I am stuck since last Monday on it. Could you post your parameters in similar fashion for comparison? If it does not violate rules of competition, I would be happy to exchange my code for sake of running comparison/learning.
Thanks in advance
Compiler: GCC 4.7.2
CPU: Intel Core i73517U, 1.90GHz
Flags used in compilation:
Wall Wextra (no output generated)
g (for debugging purpose, Valgrind returned no problems or leaks)
Ofast (slight improvement over O2 and O3)
march and mtune for corei7avx
std=gnu++11 (for vector and algorithm support)
lm
Average runtime is 26.988 seconds. Code returns correct results provided in problem statement and returns correct solution to problem itself. It is not tragic, but regardless one of my slower programs. What bothers me is the fact my solution in C11 (that I feel more proficient with) is only about 25 seconds faster. I'm sensing a lot there is to improve but I am stuck since last Monday on it. Could you post your parameters in similar fashion for comparison? If it does not violate rules of competition, I would be happy to exchange my code for sake of running comparison/learning.
Thanks in advance
 selfdemoted from 357, I want to return to this score by solving everything in C/C++.