summaryrefslogtreecommitdiffstats
path: root/mat/euler/10/prog.c
diff options
context:
space:
mode:
authorsijanec <sijanecantonluka@gmail.com>2020-12-03 17:08:39 +0100
committersijanec <sijanecantonluka@gmail.com>2020-12-03 17:08:39 +0100
commit190507a0a05e7a6292b41bec529910ecfcbb69fb (patch)
tree20105249580655bc8b5bf47ea9ebf0e543fa06e7 /mat/euler/10/prog.c
parentnaredil 8. nalogo eulerja (diff)
downloadsola-gimb-2-190507a0a05e7a6292b41bec529910ecfcbb69fb.tar
sola-gimb-2-190507a0a05e7a6292b41bec529910ecfcbb69fb.tar.gz
sola-gimb-2-190507a0a05e7a6292b41bec529910ecfcbb69fb.tar.bz2
sola-gimb-2-190507a0a05e7a6292b41bec529910ecfcbb69fb.tar.lz
sola-gimb-2-190507a0a05e7a6292b41bec529910ecfcbb69fb.tar.xz
sola-gimb-2-190507a0a05e7a6292b41bec529910ecfcbb69fb.tar.zst
sola-gimb-2-190507a0a05e7a6292b41bec529910ecfcbb69fb.zip
Diffstat (limited to '')
-rw-r--r--mat/euler/10/prog.c32
1 files changed, 32 insertions, 0 deletions
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;
+}