diff options
author | sijanec <sijanecantonluka@gmail.com> | 2020-12-03 17:08:39 +0100 |
---|---|---|
committer | sijanec <sijanecantonluka@gmail.com> | 2020-12-03 17:08:39 +0100 |
commit | 190507a0a05e7a6292b41bec529910ecfcbb69fb (patch) | |
tree | 20105249580655bc8b5bf47ea9ebf0e543fa06e7 /mat/euler/3 | |
parent | naredil 8. nalogo eulerja (diff) | |
download | sola-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 'mat/euler/3')
-rw-r--r-- | mat/euler/3/Makefile | 2 | ||||
-rwxr-xr-x | mat/euler/3/a.out | bin | 0 -> 8560 bytes | |||
-rw-r--r-- | mat/euler/3/prog.c | 35 |
3 files changed, 37 insertions, 0 deletions
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 Binary files differnew file mode 100755 index 0000000..1cb7d86 --- /dev/null +++ b/mat/euler/3/a.out 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; +} |