Guys how do I write a program that calculates the sum of all the primes up to 2 million?

guys how do I write a program that calculates the sum of all the primes up to 2 million?

Other urls found in this thread:

iluxonchik.github.io/regular-expression-check-if-number-is-prime/
twitter.com/NSFWRedditGif

Ask your teacher

1. Find list of primes up to 2 million on internet
2. Add them all together with program

write a program to find primes and sum them

Classic sieve should be sufficient desu. I have hard time understanding wheel techniques

>sieve of Eratosthenes
>add result

> He doesn't know the regular expression for prime numbers
> He doesn't know how to add
> laughing_gay_clowns.jpg

I don't think i've heard that term lol

I'll trade for composite 30 sieve if its any good lol

1. Write function which would get prime numbers from internet and return array of primes.
2. Sum(arrayOfPrimes)

Done.
Next question:
Write program to sum all primes over 2 million.

Shitty code written from my phone. Idk if it works.

Int sum = 0
Int counter =0

For(int i= 0; i

Only that? Now bubblesort all the digits in the resulting number

int main()
{
printf("142913828922");
return 0;
}

you're welcome.

sieve of eratosthenes

seriously though, is this a meme? or is Sup Forums slowly working it's way through project euler?

iluxonchik.github.io/regular-expression-check-if-number-is-prime/

c30 sieve
all primes bar 2,3,5 = [1, 7, 11, 13, 17, 19, 23, 29] mod 30
no false negatives

public static void main(String... args) {
int sum = 0;
for (int i = 0; i < 2000000; i++){
if (isPrime(i)) sum += i;
}
System.out.println("Sum: " + sum);
}

private static native boolean isPrime(int i);

Whew, that was easy.

>tfw you fell for the 16GiB RAM meme

>faggot OP fails a simple programming assignment
>Sup Forums mocks him for being an idiot and not autistic enough to remember a barely used algorithm
>this is now the new FizzBuzz meme

Nah, I have more interesting problems to suffer over.

It's a meme

>finally memorize how to sum 2 million primes
>day of interiew they role out a role out a whiteboard
>'write a program that sums all the primes under 3 million'

>Write program to sum all primes over 2 million

Gimme a moment, need to do a PhD first

int size = 2000000;
long sum = 0;

int[] primes = {2,3,5,7};

boolean[] isPrime = new boolean[size];
Arrays.fill(isPrime, true);

for(int i = 0; i < primes.length; i++){
for(int j = primes[i]*2; j < size; j+=primes[i]){
isPrime[j] = false;
}
}

for(int k = 2; k < size; k++){
if(isPrime[k] == true){
sum += k;
}
}

In all seriousness, why isn't my code working. I find all the primes but for some reason the output is 457143142877. Runs at 23ms though.

i wouldnt hire yuo