SolveLinearCongruences.tex 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. \documentclass{article}
  2. \usepackage[pdftex,active,tightpage]{preview}
  3. \setlength\PreviewBorder{2mm}
  4. \usepackage[utf8]{inputenc} % this is needed for umlauts
  5. \usepackage[ngerman]{babel} % this is needed for umlauts
  6. \usepackage[T1]{fontenc} % this is needed for correct output of umlauts in pdf
  7. \usepackage{amssymb,amsmath,amsfonts} % nice math rendering
  8. \usepackage{braket} % needed for \Set
  9. \usepackage{algorithm,algpseudocode}
  10. \usepackage{tikz}
  11. \usetikzlibrary{decorations.pathreplacing,calc}
  12. \newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node (#1) {};}
  13. \newcommand*{\AddNote}[4]{%
  14. \begin{tikzpicture}[overlay, remember picture]
  15. \draw [decoration={brace,amplitude=0.5em},decorate,very thick]
  16. ($(#3)!(#1.north)!($(#3)-(0,1)$)$) --
  17. ($(#3)!(#2.south)!($(#3)-(0,1)$)$)
  18. node [align=center, text width=2.5cm, pos=0.5, anchor=west] {#4};
  19. \end{tikzpicture}
  20. }%
  21. \begin{document}
  22. \begin{preview}
  23. \begin{algorithm}[H]
  24. \begin{algorithmic}
  25. \Require $R \in \mathbb{Z}^n, P \in (\mathbb{N}_{\geq 1})^n, n \in \mathbb{N}_{\geq 1}$, where \\
  26. $R$ is a vector with all rests $r_i$ and\\
  27. $P$ is a vector with all modulos $p_i$ such that\\
  28. ($x \equiv r_i \mod p_i$) and $\left(i \neq j \Rightarrow \Call{gcd}{p_i, p_j} = 1 \right)$
  29. \\
  30. \State $M \gets \prod_{p \in P} p$
  31. \For{$i \in \{1, \dots, n\}$}
  32. \State $M_i \gets \frac{M}{p_i} $
  33. \State $y_i \gets \Call{getMultiplicativeInverse}{M_i, R_i}$
  34. \EndFor
  35. \\
  36. \State \Return $(\sum_{i=1}^n R_i y_i M_i, M)$
  37. \end{algorithmic}
  38. \caption{Solve a system of linear congruences}
  39. \label{alg:solveCongruences}
  40. \end{algorithm}
  41. \end{preview}
  42. \end{document}