Created
November 20, 2023 06:59
-
-
Save quackduck/6c099d6e5d66a328e0005908eb0234d1 to your computer and use it in GitHub Desktop.
prime.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <math.h> | |
#define TARGET 1000000 | |
int main() { | |
long long found = 0; | |
long long num = 2; | |
while (found < TARGET) { | |
long long till = sqrtl(num); | |
long long i; | |
for (i = 2; i <= till; i++) { | |
if (num % i == 0) { | |
break; | |
} | |
} | |
if (i==till+1) { | |
found++; | |
found > TARGET - 5 || found % 1000000 == 0 ? printf("%lld: %lld\n", found, num) : 0; | |
} | |
num++; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Apple M2 - 3.9s
i3-7100U @ 2.40GHz - 40s