title: In miller rabin algorithm in check function in while loop why we use " x = mod(x, x, n) " this?
body: <p>code full link : <a href="https://aranik43.blogspot.com/2020/06/miller-rabin-primality-test.html" rel="nofollow noreferrer">Full Code link</a></p>
  <pre><code>bool check(ll a, ll d, ll n)
  {
    ll x = power(a, d, n);
  
    if (x == 1 || x == n - 1)
      return true;
  
    while (d != n - 1) 
    {
      x = mod(x, x, n);
      d = (d &lt;&lt; 1); /*** d = d * 2 ***/
  
      if (x == 1)
        return false;
      if (x == n - 1)
        return true;
    }
  
    return false;
  }
  </code></pre>