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.