summaryrefslogtreecommitdiffstats
path: root/mat/euler/12/prog.c
diff options
context:
space:
mode:
authorsijanec <sijanecantonluka@gmail.com>2020-12-05 00:35:42 +0100
committersijanec <sijanecantonluka@gmail.com>2020-12-05 00:35:42 +0100
commit0bebb5b18e1c04f12558ddef68c90ed688436a5a (patch)
tree8db8490d4a0efac0fc462eb5755ea1772c3fabb3 /mat/euler/12/prog.c
parentmat_euler_11_narejena_naloga (diff)
downloadsola-gimb-2-0bebb5b18e1c04f12558ddef68c90ed688436a5a.tar
sola-gimb-2-0bebb5b18e1c04f12558ddef68c90ed688436a5a.tar.gz
sola-gimb-2-0bebb5b18e1c04f12558ddef68c90ed688436a5a.tar.bz2
sola-gimb-2-0bebb5b18e1c04f12558ddef68c90ed688436a5a.tar.lz
sola-gimb-2-0bebb5b18e1c04f12558ddef68c90ed688436a5a.tar.xz
sola-gimb-2-0bebb5b18e1c04f12558ddef68c90ed688436a5a.tar.zst
sola-gimb-2-0bebb5b18e1c04f12558ddef68c90ed688436a5a.zip
Diffstat (limited to 'mat/euler/12/prog.c')
-rw-r--r--mat/euler/12/prog.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/mat/euler/12/prog.c b/mat/euler/12/prog.c
new file mode 100644
index 0000000..7af0f37
--- /dev/null
+++ b/mat/euler/12/prog.c
@@ -0,0 +1,33 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+int main (int argc, char ** argv) {
+ if (argc != 1 + 1) {
+ fprintf(stderr, "uporaba: %s <stevilka>, \nprimer: %s 500\n", argv[0], argv[0]);
+ return 1;
+ }
+ unsigned long int n = strtol(argv[1], NULL, 10);
+ unsigned long long int i = 1;
+ unsigned long long int j = 0;
+ unsigned long long int d = 0;
+ unsigned long long int s = 0; // dejansko trikotniško število.
+ while (1) {
+ s = s+i;
+ fprintf(stderr, "\rpreizkušam število %lld ...", i);
+ d = 0;
+ for (j = 2; j < ceill(sqrtl(s)); j++) {
+ if (s % j == 0)
+ d++;
+ }
+ d = (d*2)+2; // dva dodamo, ker sta to število samo in 1
+ if (d > n) {
+ fprintf(stdout, "\rnašel število %lld z %lld delitelji\n", s, d);
+ return 0;
+ }
+ i++;
+ if (i <= 1) // int rollover
+ break;
+ }
+ fprintf(stderr, "napaka. intager rollover pred najdenim rezultatom!\n");
+ return 2;
+}