Well, I'm not going to write the whole code. You would probably be needing a counter variable for counting the number of two and three factors.
while((num % 2 == 0) || (num % 3 ==0))
{
if (num % 2 == 0)
{
twoFactCounter++;
num /= 2;
}
else if (num % 3 == 0)
{
threeFactCount++;
num /= 3;
}
}
//cout the vars
;)