Check this piece of code


#1

int gcd(int a, int b){
if(b==0)
return a;
return(b, a%b);
}
int Solution::cpFact(int A, int B) {
int x=gcd(A,B);
if(x==1)
return A;
//cout<<x<<endl;
return cpFact(A/x,B);
//return x;
}

Tell me why this wasn’t working?


#2

Your approach is correct and it works.


#3

u have to return gcd(b,a%b) but u just wrote (b,a%b)