#include <stdio.h>

#define TEST(x, y) printf("%d, %d => %d\n", (x), (y), common_root((x),(y)))

int common_root(int a, int b)
{
	int temp;
	
	if (a == 1 || b == 1)
		return -1;
	if (a == b) {
		return a;
	}
	
	if (a > b) {
		// Swap to make sure  a < b
		temp = a;
		a = b;
		b = temp;
	} 
	
	if ((b % a) == 0) // Check if `b` divisible by `a`
		return common_root(a, b/a);
	else
	    return -1;
}

int main(void) {
	TEST(1,2);
	TEST(2,3);
	TEST(6,10);
	TEST(4, 16);
	TEST(12, 24);
	TEST(27, 81);
	TEST(36, 1296);
	return 0;
}
