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; } | |
|
Total comments: 0 | |