summaryrefslogtreecommitdiffstats
path: root/mat/euler/10
diff options
context:
space:
mode:
Diffstat (limited to 'mat/euler/10')
-rw-r--r--mat/euler/10/Makefile2
-rwxr-xr-xmat/euler/10/a.outbin0 -> 8600 bytes
-rw-r--r--mat/euler/10/prog.c32
3 files changed, 34 insertions, 0 deletions
diff --git a/mat/euler/10/Makefile b/mat/euler/10/Makefile
new file mode 100644
index 0000000..20eb4bf
--- /dev/null
+++ b/mat/euler/10/Makefile
@@ -0,0 +1,2 @@
+default:
+ gcc -pedantic prog.c -lm
diff --git a/mat/euler/10/a.out b/mat/euler/10/a.out
new file mode 100755
index 0000000..9a7b171
--- /dev/null
+++ b/mat/euler/10/a.out
Binary files differ
diff --git a/mat/euler/10/prog.c b/mat/euler/10/prog.c
new file mode 100644
index 0000000..ca82ccc
--- /dev/null
+++ b/mat/euler/10/prog.c
@@ -0,0 +1,32 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+int jePrastevilo(int u) {
+ if (u <= 1) // idk trebše je reku da 1 ni praštevilo, pomoje se sicer laže
+ return 0; // we fucked up, ne bom delal za negativne številke
+ 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 <do katerega števila>\nprimer: %s 1000000\n", argv[0], argv[0]);
+ return 1;
+ }
+ int u = atoi(argv[1]);
+ unsigned long long int s = 0;
+ if (u < 1) {
+ fprintf(stderr, "minimalno število je 1!\n");
+ return 2;
+ }
+ while (u > 1) { // js srepo zaupam žoržu, da 1 ni praštevilo.
+ if (jePrastevilo(u))
+ s = s+u;
+ u--;
+ }
+ fprintf(stdout, "konec. seštevek je %lld.\n", s);
+ return 0;
+}