summaryrefslogtreecommitdiffstats
path: root/mat/euler/7/prog.c
diff options
context:
space:
mode:
Diffstat (limited to 'mat/euler/7/prog.c')
-rw-r--r--mat/euler/7/prog.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/mat/euler/7/prog.c b/mat/euler/7/prog.c
new file mode 100644
index 0000000..e2e31a1
--- /dev/null
+++ b/mat/euler/7/prog.c
@@ -0,0 +1,30 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+int jePrastevilo(unsigned long long int u) {
+ if (u <= 1) // nah 1 ni praštevilo js sm sam neumen
+ return 0; // in praštevila so samo naravna, spet sem neumen
+ if (u == 2)
+ return 1;
+ for (int i = 2; i <= ceil(sqrt(u)); i++)
+ if (u % i == 0)
+ return 0;
+ return 1;
+}
+int main(int argc, char ** argv) {
+ if (argc != 1+1) {
+ fprintf(stderr, "uporaba: %s <st>\nprimer, ki izpiše prvih 10001 praštevil: %s 10001", argv[0], argv[0]);
+ return 1;
+ }
+ size_t m = atoi(argv[1]);
+ size_t n = 2;
+ size_t i = 0;
+ while (i < m) {
+ if (jePrastevilo(n)) {
+ fprintf(stdout, "našel %ld.: %ld\n", i+1, n);
+ i++;
+ }
+ n++;
+ }
+ return 0;
+}