#include #include using namespace std; int numDivides (int num) { int count = 0; num = abs(num); //in case number is negative while(num>0) { count++; //it can be divided once more num/=2; //divide by 2 } return count; } //The GCD of two numbers a and b is the same as the GCD of a and b%a, if b>a //We just do this recursively until one of the numbers divides the other cleanly. //This number is the GCD. //For example, consider 36 and 60 //GCD (36, 60) = GCD (36, 60%36) = GCD (36, 24) = GCD( 24, 36%24) // = GCD(24,12) = GCD(12, 24%12) = GCD(12, 0). We stop here. 12 is the GCD int GCD(int a, int b) { if(a>b) //swap, since we want a to be the smaller number { int temp =a; a=b; b=temp; } if(a == 0) return b; //a didved b cleanly in the previous iteration. //b is the CGD return GCD(a, b%a); } //you should be able to write the main function to test this