Sum all the primes under 2 million or this bird will stab you
Sum all the primes under 2 million or this bird will stab you
Other urls found in this thread:
wolframalpha.com
twitter.com
You posted this last week. Try 2 billion this time.
#define LIMIT 2000000000
#define BITS (sizeof(char) * CHAR_BIT)
/* Sieve of Eratosthenes with optimizations
* - bitpacked lookup table (2 billion in 250MB)
* - todo: double memory storage by omitting evens
* - do not check divisiblity for numbers > sqrt of n
* - do not check even numbers other than 2
*/
int main(void)
{
char *a = calloc(LIMIT / BITS, sizeof(char));
size_t i, j, sum = 0, sq = sqrt(LIMIT);
for (i = 3; i < sq; i += 2) /* skip all even numbers */
if (!(a[i / BITS] & (1
#include
#define LIMIT 2000000
char sieve[LIMIT] = { 0 };
unsigned long long primes[200000];
int count = 0;
void get_primes()
{
unsigned long i, j;
for(i = 2; i < LIMIT; ++i)
{
if(!sieve[i])
{
primes[count++] = i;
for(j = i*i; j < LIMIT; j += i)
{
sieve[j] = 1;
}
}
}
}
int main(){
unsigned long long sum = 0;
unsigned long i;
get_primes();
for(i = 0; i < count; ++i)
{
sum += primes[i];
}
printf("sum: %lld\n", sum);
}
sum: 142913828922
real 0m0.030s
user 0m0.028s
sys 0m0.000s
it even does good on a raspberry pi zero:
pi@raspberrypi:~ $ time ./a.out
sum: 142891895587
real 0m0.198s
user 0m0.180s
sys 0m0.010s
print('142913828922')
What's the sum of it?
got this one:
sum: 95673602693282040
real 0m42.693s
user 0m42.136s
sys 0m0.464s
>literally the fourth thread
>neither bans nor suicides have stopped this faggot yet
I wanted to try with 20 billion but the SSD swapping becomes unbearable.
I only have 2GB after all.
$ time ./prime
95673602693282040
real 0m50.925s
user 0m50.284s
sys 0m0.300s
[/code]
Ctrl + C
[/code]
Result :
142913828922
142913828922
well that just seems rude and unnecessary mr bird.
Can someone help me? I don't know why it doesn't work
[CODE]
#include
int main()
{
unsigned long long suma = 0;
int i = 1;
int limite = 2000000;
while (i < limite)
{
suma = suma + i;
i = i + 2;
}
printf("%llu", suma);
return 0;
}
[/CODE]
;_________________;
LOOK AT THIS RETARD
HAAHHAHAHAAH xD
What are trying to do here??
pls user no laff
i got it to do 200k
I tried to do bitpacking in JS and couldn't get started because I don't know how to create an array of 8 bit integers.
What a shit language.
Nevermind, I am completely fucking stupid. My code sums every odd number below 2 million.
I am already stabbed.
btw, how do I post code?
bump
>create list p = {n}, 0for each x, remove all y from list p whence x|y
>return sum(p)
>???
>beanus
FUCK da bunch it should be
>create list p = {n}, 0 x, such that for each x > 1, remove all y from list p whence x|y
>return sum(p)
>???
>beanus
>create list p = {n}, 0 x, such that for each x > 1, remove all y from list p whence x|y
>return sum(p)
>???
>beanus
>this language is shit because I'm too retarded to know how to use it
kys
Kill yourself, you dumb fucking shit stain.