The main point here is
gcd(b,a)= gcd(a,b%a);
Thus, here we have the big integer B(250 digits), we calculate gcd as RHS says i.e. B%a. Now, we don’t have any datatype which can accept number of 250 digits and hence, we take the number as a string. Lets say we have a three digit number ABC. The number can be expressed as:
ABC= 100*A+ 10*B + C;
(ABC)%MOD= (100*A+ 10*B +C)%MOD;
= ((100*A)%MOD + (10*B)%MOD + C%MOD)%MOD; // By the property of modulo operator
= (((100%MOD)*(A%MOD))%MOD + ((10%MOD)*(B%MOD))%MOD + C%MOD)%MOD;
or
(ABC)%MOD= (A*100)%MOD + (BC)%MOD; // this cab be expanded further in the above manner.
So, you can see here, ABC%MOD is basically modulus of the numbers which appear in the expression when we express it in the powers of 10.
So, we are as per this code calculating this way:
lets say string is 12= 10+ 2. Number in powers of 10 is the value of r in every iteration.
for(int i=0;i<len;i++)
{
r= 10*r +(b[i]-'0');
// initially r=0, number is r= 0+ (1); r=1 =(1)%4=1;` // then in next iteration, r is 1, number is
//r= 1*10 + (2)=12(see here the value of r here is the actual value represented by the string) r=12.
r=r%a;
}