📚 The CoCalc Library - books, templates and other resources
cocalc-examples / martinthoma-latex-examples / source-code / Pseudocode / SolveLinearCongruences / SolveLinearCongruences.tex
132930 viewsLicense: OTHER
\documentclass{article}1\usepackage[pdftex,active,tightpage]{preview}2\setlength\PreviewBorder{2mm}34\usepackage[utf8]{inputenc} % this is needed for umlauts5\usepackage[ngerman]{babel} % this is needed for umlauts6\usepackage[T1]{fontenc} % this is needed for correct output of umlauts in pdf7\usepackage{amssymb,amsmath,amsfonts} % nice math rendering8\usepackage{braket} % needed for \Set9\usepackage{algorithm,algpseudocode}1011\usepackage{tikz}12\usetikzlibrary{decorations.pathreplacing,calc}13\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node (#1) {};}14\newcommand*{\AddNote}[4]{%15\begin{tikzpicture}[overlay, remember picture]16\draw [decoration={brace,amplitude=0.5em},decorate,very thick]17($(#3)!(#1.north)!($(#3)-(0,1)$)$) --18($(#3)!(#2.south)!($(#3)-(0,1)$)$)19node [align=center, text width=2.5cm, pos=0.5, anchor=west] {#4};20\end{tikzpicture}21}%2223\begin{document}24\begin{preview}25\begin{algorithm}[H]26\begin{algorithmic}27\Require $R \in \mathbb{Z}^n, P \in (\mathbb{N}_{\geq 1})^n, n \in \mathbb{N}_{\geq 1}$, where \\28$R$ is a vector with all rests $r_i$ and\\29$P$ is a vector with all modulos $p_i$ such that\\30($x \equiv r_i \mod p_i$) and $\left(i \neq j \Rightarrow \Call{gcd}{p_i, p_j} = 1 \right)$31\\32\State $M \gets \prod_{p \in P} p$3334\For{$i \in \{1, \dots, n\}$}35\State $M_i \gets \frac{M}{p_i} $36\State $y_i \gets \Call{getMultiplicativeInverse}{M_i, R_i}$37\EndFor38\\39\State \Return $(\sum_{i=1}^n R_i y_i M_i, M)$40\end{algorithmic}41\caption{Solve a system of linear congruences}42\label{alg:solveCongruences}43\end{algorithm}44\end{preview}45\end{document}464748