Sunday, 09.08.2020, 19:31
Welcome Guest | RSS
Site menu
Login form
Section categories
Search
Calendar
«  June 2011  »
SuMoTuWeThFrSa
   1234
567891011
12131415161718
19202122232425
2627282930
Entries archive
Our poll
Rate my site
Total of answers: 6
Statistics

Total online: 1
Guests: 1
Users: 0
Main » 2011 » June » 10 » Finding modular inverse
17:46
Finding modular inverse
#include <iostream>

using namespace std;

int modInverse(int a, int n) {
 int i = n, v = 0, d = 1;
 while (a>0) {
  int t = i/a, x = a;
  a = i % x;
  i = x;
  x = d;
  d = v - t*x;
  v = x;
 }
 v %= n;
 if (v<0) v = (v+n)%n;
 return v;
}

int main()
{
    cout << modInverse(8,16);
    return 0;
}

Category: C++ programs | Views: 391 | Added by: H_Imirzyan | Tags: modular inverse, inverse, modul | Rating: 0.0/0
Total comments: 0
Name *:
Email *:
Code *: