Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

📚 The CoCalc Library - books, templates and other resources

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