Skip to content
Snippets Groups Projects
Commit 5d75c2c5 authored by François Lasota's avatar François Lasota
Browse files

Algo du ppcm

parent 17118fa1
Branches
No related tags found
No related merge requests found
......@@ -18,7 +18,7 @@ François LASOTA}
\newcommand{\strong}[1]{\textbf{#1}\xspace}
\renewcommand{\contentsname}{Table des matières}
\lstset{language=Python,basicstyle=\ttfamily\footnotesize ,firstnumber=0,commentstyle=\color{gray},keywordstyle=\color{magenta},numbers=left}
\lstset{language=Python,basicstyle=\ttfamily\footnotesize ,firstnumber=0,tabsize=3,commentstyle=\color{gray},keywordstyle=\color{magenta},numbers=left}
\begin{document}
\maketitle
......@@ -218,11 +218,11 @@ Il a été énoncé par Euclide dans son livre \textit{Les Éléments} numéro V
Effectivement, $12=4 \times 3$ et $8=4 \times 2$
\begin{lstlisting}[language=Python]
\begin{lstlisting}
def PGCD(A,B): # On assume que A>B
E=[] # Je n'ai pas fait l'algorithme humain, mais un algorithme plus efficace en code
for i in range(A):
if A%i==0 and B%i==0: # Si Le nombre est diviseurs de A et B.
if A%i==0 and B%i==0: # Si le nombre est diviseurs de A et B.
E.append(i)
return E[-1] # Le dernier etant le plus grand, pouvant etre 1
......@@ -243,10 +243,22 @@ def PGCD(A,B): # On assume que A>B
Ainsi, nous obtenons: $2^{3} \times 3^{1} = 24$ \newline
Donc PPCM(12,8)= 24.\newline
Effectivement, $24=12 \times 2 = 8 \times 3$.
\begin{lstlisting}
def PPCM(A,B):
FA=decomposition(A) #On prend la decomposition en facteurs premiers des 2 nombres
FB=decomposition(B)
for i in range(len(FB[0])): #On se met sur A pour y rajouter les facteurs de B
if FB[0][i] in FA[0]:
if FB[1][i]>FA[1][FA.index(FB[0][i])]:#Une longue expression pour s'assurer
FA[1][FA.index(FB[0][i])]=FB[1][i] #de ne pas modifier les mauvais elements
else:
FA[0].append(FB[0][i])
FA[1].append(FB[1][i])
resultat=0
for i in range(len(FA[0]):
resultat+= FA[0][i]**FA[1][i]
return resultat
\end{lstlisting}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment