Share
Explore BrainMass

Chinese Remainder Theorem Visual C++.NET 2003

I need help to writing a program "VC++.net"with the specified input and output.

Please, Implement the Chinese Remainder Theorem. Allowing at least 3 pairwise relatively prime positive integers.

Example:
Problem #1
Solve

p1: x = 2 (mod 3)
p2: x = 3 (mod 5)
p3: x = 2 (mod 7)

From p1, x = 3t + 2, for some integer t. Substituting this into p2 gives 3t = 1 (mod 5). Looking up 1/3 in the division table modulo 5, this reduces to a simpler equation

p4: t = 2 (mod 5)

which, in turn, is equivalent to t = 5s + 2 for an integer s. Substitution into x = 3t + 2 yields x = 15s + 8. This now goes into p3: 15s + 8 = 2 (mod 7). Casting out 7 gives s = 1 (mod 7). From here, s = 7u + 1 and, finally, x = 105 u& + 23.

Note that 105 = lcm(3, 5, 7). Thus we have solutions 23, 128, 233, ...

This program must run in the Visual C++.NET. Some time I have problem with that, so, please the whole project included in the attached Zip file.

Solution Preview

The Visual Studio .net project is attached in file chi.zip.
I hope you have no difficulty using it but, just in case, I also attached the executable chi.exe

As you have not specified your preference on the form of user interface, I made it a Dialog - it is much more convenient for ...

$2.19