Facing problem for the larger values


#1

why my code is not working for larger value?
int Solution::sqrt(int A) {
int s=0,e=A,ans=-1;

while(s<=e){
int mid=(s+e)/2;

if(mid*mid==A)
 return mid;
 else if(mid*mid>A)
  e=mid-1;
  else if(mid*mid<A){
   ans=mid;
   s=mid+1;
}

}
return ans;
}


#2

use long for every variable . s, e and mid