A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 deletions
20
Task/Modular-inverse/C/modular-inverse.c
Normal file
20
Task/Modular-inverse/C/modular-inverse.c
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int mul_inv(int a, int b)
|
||||
{
|
||||
int b0 = b, t, q;
|
||||
int x0 = 0, x1 = 1;
|
||||
if (b == 1) return 1;
|
||||
while (a > 1) {
|
||||
q = a / b;
|
||||
t = b, b = a % b, a = t;
|
||||
t = x0, x0 = x1 - q * x0, x1 = t;
|
||||
}
|
||||
if (x1 < 0) x1 += b0;
|
||||
return x1;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
printf("%d\n", mul_inv(42, 2017));
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue