x = k*s;
while (x > n)
{
x = floor(( k*(x-n) - 1.0 )/ (k-1.0) );
count++;
}
In the above code n, k, s integers <= 1000000. Whenver x goes out of range of integer it gives me wrong output. I tried making it unsigned long long but still I am getting wrong answer. Can someone help me out in this?
Though x was unsigned long since k and s were integers, they were being saved in an intermediate integer variable and was then converted to unsigned long. Hence wrong result. Now its correct.