Finding remainders progressively

0 votes
asked Sep 11, 2017 by danish-sodhi

I have a number say 345691. I want to find remainders in backward direction.Say :

first_remainder=1%b
second_remainder=91%b
third_remainder=691%b
fourth_remainder=5691%b
.
.
.
last_remainder=345691%9;

I came across following formulation:

current_remainder = (currentdigit * P +previous_remainder) % b; P=10^(lenght ofnumber-1)

I tried understanding but could not understand the roots of this formulation. Can some one help me understand why it works ?

1 Answer

0 votes
answered Sep 11, 2017 by nullpointer
345691 => 1 + 9*10 + 6*100 + 5*1000 + 4 *10000 + 3*100000

that's probably the simplest way you can correlate the formulation. Further more, to relate more variables -

=> 1*10^0 + 9*10^1 + 6*10^2 + 5*10^3 + 4*10^4 + 3*10^5

=> ....... + 3*10^(number.length -1)
Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
Website Online Counter

...