Array ( [0] => [1] => questions [2] => Arrays [3] => Modular-inversion )
Login to see Discussion
i)create a method modinverse and which takes a and m as argument
ii)assign m to m1 , 0 to y and 1 to x
iii)if m equal to 1 return 0
iv)while a is greater than 1 assign a/m to q, t to a,update m to a%m,a to t, t to y and finally assign x-qy to x and t ot x
v)if x is less than 0 add m1 to x
vi)return the value of x
vii)in main method take the required input from the user and print the output
Time Complexity:
Space Complexity: O(1)
Note :
Let us know if you can come up with a better approach, mail us at support@theinquisitive.in Your approach will be reviewed and posted with credits to you.
Login to see Solution