Monday, August 23, 2010

Mod on Sequences

While solving a problem at one of the Programming Practice sites, I came to know this about sum of a sequence. I wonder how much lacking do I have in Maths.

If, for example, 1+2+3+.......+(n-1)+n is the sequence that you want the sum of then, what we do is
add all the numbers from 1 to n. But this has another method. Whenever the sum crosses n during the the summation process you can take it as sum%n.

Which means, (1+2+3+.........+n)%n = (sum+1)%n + (sum+2)%n + ...... + ( sum+n)%n.

I didn't get it from any book so not sure if it's wrong or right. If someone finds it a mistake please comment.

No comments:

Post a Comment

Post your comment here. If you want to say something about programming problems, scripts, software etc, please try to be as descriptive as possible.

Connect Rapoo MT750S with Linux (Tested on Manjaro)

 I bought this obvious copy of MX Master 2S in hopes of having the device switching functionality along with a lightweight body because I ha...