Is there a way to implement an algorithm for calculating (b^n) % k, without overflowing? b is a double and n and k are integers.
Using modulo operator inside the for loop while multiplying doesn't produce the correct result
double res = 1.0;
double b = Math.Sqrt(13);
int n = 2000;
int k = 1000000007;
for (int i = 0; i < n; i++)
{
res = (res * b) % k;
}Any ideas?