summaryrefslogtreecommitdiffstats
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
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
-rw-r--r--mat/euler/1/Makefile2
-rwxr-xr-xmat/euler/1/a.outbin0 -> 8480 bytes
-rw-r--r--mat/euler/1/prog.c23
-rw-r--r--mat/euler/10/Makefile2
-rwxr-xr-xmat/euler/10/a.outbin0 -> 8600 bytes
-rw-r--r--mat/euler/10/prog.c32
-rw-r--r--mat/euler/2/Makefile2
-rwxr-xr-xmat/euler/2/a.outbin0 -> 8432 bytes
-rw-r--r--mat/euler/2/prog.c33
-rw-r--r--mat/euler/3/Makefile2
-rwxr-xr-xmat/euler/3/a.outbin0 -> 8560 bytes
-rw-r--r--mat/euler/3/prog.c35
-rw-r--r--mat/euler/4/Makefile2
-rwxr-xr-xmat/euler/4/a.outbin0 -> 8576 bytes
-rw-r--r--mat/euler/4/prog.c28
-rw-r--r--mat/euler/5/Makefile2
-rwxr-xr-xmat/euler/5/a.outbin0 -> 8480 bytes
-rw-r--r--mat/euler/5/prog.c26
-rw-r--r--mat/euler/6/Makefile2
-rwxr-xr-xmat/euler/6/a.outbin0 -> 8472 bytes
-rw-r--r--mat/euler/6/prog.c20
-rw-r--r--mat/euler/7/Makefile2
-rwxr-xr-xmat/euler/7/a.outbin0 -> 8552 bytes
-rw-r--r--mat/euler/7/prog.c30
-rw-r--r--mat/euler/9/Makefile2
-rwxr-xr-xmat/euler/9/a.outbin0 -> 8568 bytes
-rw-r--r--mat/euler/9/prog.c24
27 files changed, 269 insertions, 0 deletions
diff --git a/mat/euler/1/Makefile b/mat/euler/1/Makefile
new file mode 100644
index 0000000..2def8af
--- /dev/null
+++ b/mat/euler/1/Makefile
@@ -0,0 +1,2 @@
+default:
+ gcc prog.c
diff --git a/mat/euler/1/a.out b/mat/euler/1/a.out
new file mode 100755
index 0000000..abe5144
--- /dev/null
+++ b/mat/euler/1/a.out
Binary files differ
diff --git a/mat/euler/1/prog.c b/mat/euler/1/prog.c
new file mode 100644
index 0000000..f152200
--- /dev/null
+++ b/mat/euler/1/prog.c
@@ -0,0 +1,23 @@
+#include <stdio.h>
+#include <stdlib.h>
+int main (int argc, char ** argv) {
+ if (argc != 1+3) {
+ fprintf(stderr, "uporaba: %s <max> <a> [b c d e ...]\nprimer, ki do 1000 izpiše večkratnike 3 ali 5: %s 1000 3 5\n", argv[0], argv[0]);
+ return 1;
+ }
+ unsigned long int m = strtoll(argv[1], NULL, 10);
+ unsigned long int * n = malloc(sizeof(unsigned long int)*argc-2);
+ size_t i = 0;
+ size_t j = 0;
+ unsigned long int s = 0; // Seštevek
+ for (i = 0; i < argc-2; i++)
+ n[i] = strtoll(argv[i+2], NULL, 10);
+ for (i = 1; i < m; i++)
+ for (j = 0; j < argc-2; j++)
+ if (i % n[j] == 0) {
+ s = s + i;
+ break; // da štejemo samo enkrat
+ }
+ fprintf(stdout, "konec. seštevek je %ld.\n", s);
+ return 0;
+}
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;
+}
diff --git a/mat/euler/2/Makefile b/mat/euler/2/Makefile
new file mode 100644
index 0000000..2def8af
--- /dev/null
+++ b/mat/euler/2/Makefile
@@ -0,0 +1,2 @@
+default:
+ gcc prog.c
diff --git a/mat/euler/2/a.out b/mat/euler/2/a.out
new file mode 100755
index 0000000..5b7faf9
--- /dev/null
+++ b/mat/euler/2/a.out
Binary files differ
diff --git a/mat/euler/2/prog.c b/mat/euler/2/prog.c
new file mode 100644
index 0000000..607417c
--- /dev/null
+++ b/mat/euler/2/prog.c
@@ -0,0 +1,33 @@
+#include <stdio.h>
+#include <stdlib.h>
+int main (int argc, char ** argv) {
+ if (argc != 1+2) {
+ fprintf(stderr, "uporaba: %s <max> <delitelj>\nprimer, ki sešteje vsa liha fibonačijeva števila do 2M: %s 2000000 -2\nče je deljenec negativen, se seštejejo števila, ki NISO deljiva z deliteljem\n", argv[0], argv[0]);
+ return 1;
+ }
+ unsigned long int s = strtoll(argv[1], NULL, 10); // makSimalno
+ unsigned long int d = strtoll(argv[2], NULL, 10); // Delitelj
+ unsigned short int o = (llabs(d) == d);
+ d = llabs(d);
+ unsigned long int i = 1;
+ unsigned long int j = 2;
+ unsigned long int c = 0; // Carry
+ unsigned long int e = 0; // sEštevek
+ while (i <= s) {
+ fprintf(stderr, "i = %ld, seštevek = %ld\n", i, e);
+ if (o) {
+ if (i % d == 0) {
+ e = e + i;
+ }
+ } else {
+ if (i % d != 0) {
+ e = e + i;
+ }
+ }
+ c = i + j;
+ i = j;
+ j = c;
+ }
+ fprintf(stdout, "\rseštevek števil do %ld, ki z %ld %s deljiva: %ld\n", s, d, o ? "so" : "niso", e);
+ return 0;
+}
diff --git a/mat/euler/3/Makefile b/mat/euler/3/Makefile
new file mode 100644
index 0000000..156bc0d
--- /dev/null
+++ b/mat/euler/3/Makefile
@@ -0,0 +1,2 @@
+default:
+ gcc prog.c -lm
diff --git a/mat/euler/3/a.out b/mat/euler/3/a.out
new file mode 100755
index 0000000..1cb7d86
--- /dev/null
+++ b/mat/euler/3/a.out
Binary files differ
diff --git a/mat/euler/3/prog.c b/mat/euler/3/prog.c
new file mode 100644
index 0000000..753b1fb
--- /dev/null
+++ b/mat/euler/3/prog.c
@@ -0,0 +1,35 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+int jePrastevilo(int u) {
+ if (u <= 1)
+ return 0;
+ 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 <stevilo>\nprimer: %s 600851475143\n", argv[0], argv[0]);
+ return 1;
+ }
+ unsigned long long p = 0;
+ unsigned long long n = strtoll(argv[1], NULL, 10);
+ unsigned long long i = 1;
+ unsigned long long k = ceil(sqrt(n))+1;
+ while (i < k) {
+ i = i + 2;
+ if (!jePrastevilo(i))
+ continue;
+ if (n % i == 0)
+ p = i;
+ if (1==1) {
+ fprintf(stderr, "%lld, i = %lld, k = %lld, n = %lld\r", (i/k)*100, i,k,n);
+ }
+ }
+ fprintf(stdout, "\rkonec. našel največje praštevilo %lld: %lld\n", n, p);
+ return 0;
+}
diff --git a/mat/euler/4/Makefile b/mat/euler/4/Makefile
new file mode 100644
index 0000000..2def8af
--- /dev/null
+++ b/mat/euler/4/Makefile
@@ -0,0 +1,2 @@
+default:
+ gcc prog.c
diff --git a/mat/euler/4/a.out b/mat/euler/4/a.out
new file mode 100755
index 0000000..336eb2e
--- /dev/null
+++ b/mat/euler/4/a.out
Binary files differ
diff --git a/mat/euler/4/prog.c b/mat/euler/4/prog.c
new file mode 100644
index 0000000..151dea9
--- /dev/null
+++ b/mat/euler/4/prog.c
@@ -0,0 +1,28 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+int main(int argc, char ** argv) {
+ if (argc != 1+2) {
+ fprintf(stderr, "uporaba: %s <min> <max>\nprimer: %s 100 999\n", argv[0], argv[0]);
+ return 1;
+ }
+ size_t i, k;
+ unsigned long long int d = 0;
+ unsigned long long int j[2];
+ unsigned long long int min = atoi(argv[1]);
+ unsigned long long int max = atoi(argv[2]);
+ unsigned long long int step = 1;
+ char s[256] = "";
+ for (j[0] = min; j[0] <= max; j[0]++)
+ for (j[1] = min; j[1] <= max; j[1]++) {
+ sprintf(s, "%lld", j[0]*j[1]);
+ i = strlen(s);
+ for (k = 0; k < i; k++)
+ if (s[k] != s[(i-1)-k])
+ break;
+ else if (k >= i-1 && d < j[0]*j[1])
+ d = j[0]*j[1];
+ }
+ fprintf(stdout, "konec. našel največji palindrom %lld.\n", d);
+ return 0;
+}
diff --git a/mat/euler/5/Makefile b/mat/euler/5/Makefile
new file mode 100644
index 0000000..2def8af
--- /dev/null
+++ b/mat/euler/5/Makefile
@@ -0,0 +1,2 @@
+default:
+ gcc prog.c
diff --git a/mat/euler/5/a.out b/mat/euler/5/a.out
new file mode 100755
index 0000000..18403da
--- /dev/null
+++ b/mat/euler/5/a.out
Binary files differ
diff --git a/mat/euler/5/prog.c b/mat/euler/5/prog.c
new file mode 100644
index 0000000..14ce34e
--- /dev/null
+++ b/mat/euler/5/prog.c
@@ -0,0 +1,26 @@
+#include <stdio.h>
+#include <stdlib.h>
+int main (int argc, char ** argv) {
+ if (argc != 1+1) {
+ fprintf(stderr, "uporaba: %s <stevilka>\nprimer: %s 20\n", argv[0], argv[0]);
+ return 1;
+ }
+ size_t i = 1;
+ size_t j = 1;
+ size_t m = atoi(argv[1]);
+ while (1) {
+ for (j = 1; j <= m; j++)
+ if (i % j != 0)
+ break;
+ else if (j >= m) {
+ fprintf(stdout, "našel: %ld\n", i);
+ return 0;
+ }
+ i++;
+ // fprintf(stderr, "debug: %ld\n", i);
+ if (i <= 1) // intager overrun
+ break;
+ }
+ fprintf(stderr, "ni bilo najdeno pred obratom števca. povečajte števec.\n");
+ return 1;
+}
diff --git a/mat/euler/6/Makefile b/mat/euler/6/Makefile
new file mode 100644
index 0000000..156bc0d
--- /dev/null
+++ b/mat/euler/6/Makefile
@@ -0,0 +1,2 @@
+default:
+ gcc prog.c -lm
diff --git a/mat/euler/6/a.out b/mat/euler/6/a.out
new file mode 100755
index 0000000..07b6490
--- /dev/null
+++ b/mat/euler/6/a.out
Binary files differ
diff --git a/mat/euler/6/prog.c b/mat/euler/6/prog.c
new file mode 100644
index 0000000..5a17cea
--- /dev/null
+++ b/mat/euler/6/prog.c
@@ -0,0 +1,20 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+int main (int argc, char ** argv) {
+ if (argc != 1+1) {
+ fprintf(stderr, "uporaba: %s <koliko>\nprimer: %s 100\n", argv[0], argv[0]);
+ return 1;
+ }
+ unsigned long int i = 1;
+ unsigned long int m = atoi(argv[1]);
+ unsigned long long int s = 0;
+ unsigned long long int z = 0;
+ for (i = 1; i <= m; i++) {
+ s = s + pow(i, 2);
+ z = z + i;
+ }
+ z = pow(z, 2);
+ fprintf(stdout, "konec. %lld - %lld = %lld\n", z, s, z-s);
+ return 0;
+}
diff --git a/mat/euler/7/Makefile b/mat/euler/7/Makefile
new file mode 100644
index 0000000..156bc0d
--- /dev/null
+++ b/mat/euler/7/Makefile
@@ -0,0 +1,2 @@
+default:
+ gcc prog.c -lm
diff --git a/mat/euler/7/a.out b/mat/euler/7/a.out
new file mode 100755
index 0000000..a413062
--- /dev/null
+++ b/mat/euler/7/a.out
Binary files differ
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;
+}
diff --git a/mat/euler/9/Makefile b/mat/euler/9/Makefile
new file mode 100644
index 0000000..20eb4bf
--- /dev/null
+++ b/mat/euler/9/Makefile
@@ -0,0 +1,2 @@
+default:
+ gcc -pedantic prog.c -lm
diff --git a/mat/euler/9/a.out b/mat/euler/9/a.out
new file mode 100755
index 0000000..103d407
--- /dev/null
+++ b/mat/euler/9/a.out
Binary files differ
diff --git a/mat/euler/9/prog.c b/mat/euler/9/prog.c
new file mode 100644
index 0000000..6aee0e9
--- /dev/null
+++ b/mat/euler/9/prog.c
@@ -0,0 +1,24 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+int main(int argc, char ** argv) {
+ if (argc != 1+4) {
+ fprintf(stderr, "uporaba: %s <sestevek a+b+c> <min> <max> <step>\nprimer: %s 1000 1 100 1\n", argv[0], argv[0]);
+ return 1;
+ }
+ unsigned int i;
+ double j[3];
+ double n[1];
+ double min = atoi(argv[2]);
+ double max = atoi(argv[3]);
+ double step = atoi(argv[4]);
+ for (i = 1; i <= 1; i++)
+ n[i-1] = atof(argv[i]);
+ for (j[0] = min; j[0] <= max; j[0]++)
+ for (j[1] = min; j[1] <= max; j[1]++)
+ for (j[2] = min; j[2] <= max; j[2]++)
+ if ((j[0] < j[1] < j[2]) && (j[0] + j[1] + j[2] == n[0])
+ && (pow(j[0],2) + pow(j[1],2) == pow(j[2],2)))
+ fprintf(stdout, "našel: %f^2 + %f^2 = %f^2 ; %f+%f+%f=%f\n", j[0],j[1], j[2], j[0], j[1], j[2], j[0]+j[1]+j[2]);
+ return 0;
+}