Solved

Inverse Modular

Posted on 2003-02-23
Medium Priority
298 Views
Hi,

I'm studying C++ and I have to create a program that caculates the inverse modular using two numbers as inputs ( x and m ) and one output ( n ), the inverse modular.

Can anyone give me a hand with the math behind it?

Thanks!
0
Question by:Emilio06
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 9

Expert Comment

ID: 8004127
hi

i'm from argentina, and i'm not so familiar with maths expresions

so, if you clarify what inverse modular is maybe i can help you
0

LVL 8

Expert Comment

ID: 8004570
0

LVL 3

Expert Comment

ID: 8005370
you are fast Exceter!
0

LVL 8

Expert Comment

ID: 8005416
I am? Thanks!
0

Author Comment

ID: 8005909
Exceter, can you please demonstrate the process in the link you've given my in your own words, using the variables i defined?

Thanks.
0

LVL 8

Accepted Solution

Exceter earned 550 total points
ID: 8006059
>> Exceter, can you please demonstrate the process in the link you've given my in your own words, using the variables i defined?

I don't think I can do a better job than did Doctor Wilkinson. That was a pretty good explanation.

Exceter
0

Author Comment

ID: 8017431

btw this is the function:

int modinverse(int x,int n)

{                                           int kn,a,la,q,t;
kn=n;
x%=n;
if (x<0) x+=n;
a=1;      la=0;
while (x>1)
{                                      q=n/x;
t=la-a*q; la=a; a=t;
t=n-x*q;  n=x;  x=t;
}
if   (x==0) return 0;
if (a<0) a+=kn;

return a;
}
0

LVL 8

Expert Comment

ID: 8017568
Why the C? You asked for help with the math and that is exactly what I gave you.
0

Author Comment

ID: 8021576
0

LVL 8

Expert Comment

ID: 8021773
But why the C?
0

Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, whâ€¦
Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and â€¦
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses
Course of the Month12 days, 22 hours left to enroll