notes

Personal notes
git clone git://git.laack.co/notes.git
Log | Files | Refs

DivisionAlgorithm.md (794B)


      1 # Division Algorithm
      2 
      3 **Source:** Cryptography and Network Security
      4 
      5 **Chapter:** 2.1
      6 
      7 **Definition:** The division algorithm is the theorem that given a = qn + r, 0 <= r < n; q = floor(a/n).
      8 
      9 This basically states that when r (the remainder) is greater than 0 (always), and less than n then the quotient is equivalent to the floor of the numerator divided by the denominator.
     10 
     11 ### Implementation in code to solve the Division Algorithm
     12 
     13 ```cpp
     14 
     15 #include "iostream"
     16 
     17 int main(){
     18 	int a = 37;
     19 	int n = 13;
     20 
     21 	std::cout << "Dividing ";
     22 	std::cout << a << std::endl;
     23 
     24 	std::cout << "By ";
     25 	std::cout << n << std::endl;
     26 
     27 	// implicit floor
     28 	int q = a / n;
     29 	int r = a - (q*n);
     30 
     31 	std::cout << "We get ";
     32 	std::cout << q << std::endl;
     33 
     34 	std::cout << "Remainder ";
     35 	std::cout << r << std::endl;
     36 
     37 }
     38 
     39 ```