add ipi6
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
\documentclass[uebung]{../../../lecture}
|
||||
|
||||
\usepackage{listings}
|
||||
|
||||
\title{Übungsblatt 6}
|
||||
\author{Samuel Weidemaier, Christian Merten}
|
||||
|
||||
\usepackage{xcolor}
|
||||
|
||||
\lstdefinestyle{mystyle}{
|
||||
commentstyle=\color{gray},
|
||||
keywordstyle=\color{blue},
|
||||
numberstyle=\tiny\color{gray},
|
||||
stringstyle=\color{black},
|
||||
basicstyle=\ttfamily\footnotesize,
|
||||
breakatwhitespace=false,
|
||||
breaklines=true,
|
||||
captionpos=b,
|
||||
keepspaces=true,
|
||||
numbers=left,
|
||||
numbersep=5pt,
|
||||
showspaces=false,
|
||||
showstringspaces=false,
|
||||
showtabs=false,
|
||||
tabsize=2
|
||||
}
|
||||
|
||||
\lstset{style=mystyle}
|
||||
|
||||
\begin{document}
|
||||
|
||||
\punkte
|
||||
|
||||
\begin{aufgabe}
|
||||
siehe Blatt.
|
||||
\end{aufgabe}
|
||||
|
||||
\begin{aufgabe} Primfaktorzerlegung
|
||||
\begin{lstlisting}[language=C++, title=Primfaktorzerlegung, captionpos=b]
|
||||
#include "cpp_headers/fcpp.hh"
|
||||
|
||||
int main() {
|
||||
int n = enter_int("Please enter a natural number: ");
|
||||
// search smallest factor, start with smallest possible: 2
|
||||
int k=2;
|
||||
// go until sqrt(n)
|
||||
while (k <= sqrt(n)) {
|
||||
// k is factor of n
|
||||
if (n % k == 0) {
|
||||
// print out the factor k
|
||||
print(k);
|
||||
// reset n to the quotient
|
||||
n = n / k;
|
||||
// restart at k=2
|
||||
k = 2;
|
||||
} else {
|
||||
// if k is not a factor, check next one
|
||||
k++;
|
||||
}
|
||||
}
|
||||
// n is the last prime factor of the original input number
|
||||
print(n);
|
||||
}
|
||||
\end{lstlisting}
|
||||
|
||||
Die algorithmische Komplexität des Programms für $n$ Primzahl ist $\sqrt{n}$, da die Schleife
|
||||
für Primzahlen bis $\sqrt{n} $ durchlaufen wird.
|
||||
\end{aufgabe}
|
||||
|
||||
\begin{aufgabe}
|
||||
siehe \textit{taschenrechner.cpp}
|
||||
|
||||
\end{aufgabe}
|
||||
|
||||
\end{document}
|
||||
Reference in New Issue
Block a user