From 7f3dd95837590b5b3dc973ba7f40ef184e4af7a9 Mon Sep 17 00:00:00 2001 From: Louis Date: Mon, 25 Sep 2023 14:21:29 +0200 Subject: [PATCH] vault backup: 2023-09-25 14:21:29 --- Algo/Séminaire/Exercices seminaire.md | 29 ++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/Algo/Séminaire/Exercices seminaire.md b/Algo/Séminaire/Exercices seminaire.md index 68be4dd..0299035 100644 --- a/Algo/Séminaire/Exercices seminaire.md +++ b/Algo/Séminaire/Exercices seminaire.md @@ -427,4 +427,31 @@ let power x n = match n with | n -> p (x*x) (n/2) *. (if n mod 2 = 1 then x else 1.) in p x n) ;; -``` \ No newline at end of file +``` + +Complexity : +$$ +x^0 -> 1 \ | \ +x^1 -> (x^0)^2 -> 2 \ | \ +x^2 -> x^1 -> 3 \ | \ +x^4 -> x^2 -> 4 \ | \ +x^8 -> x^4 -> 5 \ | \ +x^16 -> x^8 -> 6 \ | \ +x^(2^k) -> x^(2^k-1) -> k+2 \approx{k} \ | \ +n = 2^k -> K*log(n) \ | \ +log(n) = log(2^k) = k +$$ +$$ += O(log(n)) +$$ +## 4.12 - Prime number +```Ocaml +let prime n = + if n < 1 then + invalid_args "n should not be inferior to zero" + else + let rec p n = + if n = 0 then + 1 + else + \ No newline at end of file