CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Apr 2007
    Location
    Mars NASA Station
    Posts
    1,436

    Modular Arithmetic

    Hello to all, i try to implement modular arithmetic in C++ but finding it quite difficult to understand what is modular arithmetic.

    I reading a book title: Algorithms by S. Dagupta, C H Papadimitriu, and U. V. Vaziran in chapter 1.


    Substitution rule If x  x0 (mod N) and y  y0 (mod N), then:
    x + y  x0 + y0 (mod N) and xy  x0y0 (mod N):

    x + (y + z)  (x + y) + z (mod N) Associativity
    xy  yx (mod N) Commutativity
    x(y + z)  xy + yz (mod N) Distributivity
    This content is taken from http://www.cs.berkeley.edu/~vazirani...thms/chap1.pdf


    I hope someone can explain this to us.

    Thanks for your help.
    Thanks for your help.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: Modular Arithmetic

    Quote Originally Posted by Peter_APIIT View Post
    Hello to all, i try to implement modular arithmetic in C++ but finding it quite difficult to understand what is modular arithmetic.

    I reading a book title: Algorithms by S. Dagupta, C H Papadimitriu, and U. V. Vaziran in chapter 1.
    Did you read this book or you only copied/pasted this "Substitution rule"?
    Victor Nijegorodov

  3. #3
    Join Date
    Feb 2009
    Location
    Ukraine
    Posts
    64

    Re: Modular Arithmetic

    What exactly do you implement? Modular arithmetic covers a lot... Anything, somehow related to remainders and integer division...
    The signature (x op y) (mod N) means, in terms of C++, that ((x % N) op (y % N)), where x, y - integers, op - some operator.
    Anything more could be provided until you make yourself ask more specific question...

  4. #4
    Join Date
    Apr 2007
    Location
    Mars NASA Station
    Posts
    1,436

    Re: Modular Arithmetic

    I just need the explanation of associative, commutative and distributive law of modular arithmetic.

    Thanks.
    Thanks for your help.

  5. #5
    Join Date
    Apr 2007
    Location
    Mars NASA Station
    Posts
    1,436

    Re: Modular Arithmetic

    Anyone.
    Thanks for your help.

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: Modular Arithmetic

    What *explanations* do you need?
    Well, try http://www.google.com/search?source=...metic&aq=f&oq=
    Victor Nijegorodov

  7. #7
    Join Date
    Apr 2007
    Location
    Mars NASA Station
    Posts
    1,436

    Re: Modular Arithmetic

    What is this ?

    xy mod n = [(x mod n)×(y mod n)] mod n

    Can you list all associative, commutative and distributive law for modular arithmetic ?

    Thanks.
    Thanks for your help.

  8. #8
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: Modular Arithmetic

    Victor Nijegorodov

  9. #9
    Join Date
    Apr 2004
    Posts
    102

    Re: Modular Arithmetic

    If you need to get your head around this stuff, just make up some simple problems and work them by hand in -fraction- form.

    i.e. 7 divided by 2 == 7/2 (improper fraction) == 3 1/2 (mixed number) == 3 + 1/2 (additive form) == 3 rem. 1 (remainder form)

    Play with the math in these different forms and you'll be able to work through the distributive property, etc. from basic algebra.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured