title: python vs cpp behaving differently
body: <p>Both program are of finding number of common divisors of two numbers.</p>
  
  <p>INPUT:a=100000 b=100000</p>
  
  <blockquote>
    <p>python 36 (correct)</p>
    
    <p>cpp  35 (wrong)</p>
  </blockquote>
  
  <p>First i find gcd of two numbers and then finding the factors of gcd to obtain common divisors.
  I find the python program from <a href="https://www.w3resource.com/python-exercises/basic/python-basic-1-exercise-29.php" rel="nofollow noreferrer">here</a>
  and i tried to convert it into cpp but i am getting wrong answer.</p>
  
  <p>python:</p>
  
  <pre><code>    def ngcd(x, y):
          i=1
          while(i&lt;=x and i&lt;=y):
              if(x%i==0 and y%i == 0):
                  gcd=i;
              i+=1
          return gcd;
      def num_comm_div(x, y):
        n = ngcd(x, y)
        result = 0
        z = int(n**0.5)
        i = 1
        while( i &lt;= z ):
          if(n % i == 0):
            result += 2 
            if(i == n/i):
              print("I am executed at ",i)  # never executed
              result-=1
          i+=1
        return result
  
      print("Number of common divisors: ",num_comm_div(2, 4))
      print("Number of common divisors: ",num_comm_div(2, 8))
      print("Number of common divisors: ",num_comm_div(100000, 100000))
  </code></pre>
  
  <p>cpp:</p>
  
  <pre><code>    #include&lt;bits/stdc++.h&gt;
      #include&lt;cmath&gt;
      using namespace std;
      int gcd(int a,int b){
          if(b==0)
              return a;
          return gcd(b,a%b);
      }
  
  
      int main(){
          int t;
          cin&gt;&gt;t;
          while(t--){
              int a,b;
              cin&gt;&gt;a&gt;&gt;b;
              int n = gcd(a,b);
              cout&lt;&lt;n&lt;&lt;endl;
              int ans=0;
              for(int i=1;i&lt;=(int)sqrt(n);i++){
                  if(n%i==0){
                      ans+=2;
                  }
                  if(i==n/i)
                  {
                      printf("I am executed at %d  \n",i);//executed at i=316
                      ans--;
                  }
              }
              cout&lt;&lt;ans&lt;&lt;endl;
          }
      }
  </code></pre>