[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

How do I write a function summing the primes to two million?

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 15
Thread images: 2

File: IMG_0112.jpg (36KB, 418x438px) Image search: [Google]
IMG_0112.jpg
36KB, 418x438px
How do I write a function summing the primes to two million?
>>
>>8806907
get the list of the first two million primes
add them up
done
>>
>>8806907
sieve, sum
>>
>>8806907
>Create a sieve
>Find all the primes up to 2 million
>Put them in a list, or your data structure of choice
>Sum

Easy.
>>
This is like five lines of code lmao
>>
>>8806907
#include <iostream>
#include <vector>

int main(){
std::vector<bool> primes;
primes.resize(2000001);
primes.flip();
primes[0]=false;
primes[1]=false;
unsigned long long sum=0;
for(size_t i = 2; i<=2000000; i++){
if(primes[i]){
sum+=i;
for(size_t j=i*i; j<=2000000; j+=i){
primes[j]=false;
}
}
}

std::cout<<sum;
}

142913828922
>>
>>8806927
Lmao
>>
Problem 10 and already tapped out.

https://projecteuler.net/problem=10
>>
>>8806917
you dont see anything wrong with this??
>>
File: NoF0BVO.jpg (42KB, 640x427px) Image search: [Google]
NoF0BVO.jpg
42KB, 640x427px
[math] \sum_{k=1}^{2000000} p_k [/math] where [math] p_k [/math] is the kth prime. Easy OP :^)
>>
where did this 2 million primes meme come from? I suppose it's some new "smart person" movie or tv show
>>
>>8808328
>https://projecteuler.net/problem=10
>>
>>8806907
Www.4chan.org/g
>>
>>8806907
I'm not doing your homework
>>
let a be sum of all primes to two million

f(x)=a
Thread posts: 15
Thread images: 2


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.