Skip to content

Instantly share code, notes, and snippets.

@quackduck
Created November 20, 2023 06:59
Show Gist options
  • Save quackduck/6c099d6e5d66a328e0005908eb0234d1 to your computer and use it in GitHub Desktop.
Save quackduck/6c099d6e5d66a328e0005908eb0234d1 to your computer and use it in GitHub Desktop.
prime.c
#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;
}
@quackduck
Copy link
Author

Apple M2 - 3.9s
i3-7100U @ 2.40GHz - 40s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment