The first mathematician: F
The second mathematician: S
F has $x$ and S has $y$.
F thinks that S has a number in the form of $6^{12/x}$ or $6^{12}/x$.
S thinks that F has a number in the form of $6^{12/y}$ or $6^{12}/y$.
Let's say $G_1=\{2,3,4,6,12\}$ are the sets of number that can be used in $6^{12/z}$ and $6^{12}/z$ to get a whole number (I didn't include $1$ for obvious reasons). The numbers between $12$ and $6^{12}$ can not be used in $6^{12/z}$ because it wouldn't be whole number. We call the set of numbers greater than $12$ as $G_2$.
Now if F has a number $G_1$ then S could have a number in $G_1$ or $G_2$. If F has a number in $G_2$ then S would have a number in $G_2$, then F could easily divide $6^12$ to his number to get S's number. F says I don't know, which means he has a number in $G_1$. S has the same argument, S is also confused.
F says "I don't know your number". S thinks if F does not know my number then he is in my condition. He must have a number in $G_1$. since I know my number I just solve the equation $y^x=6^{12}$ to get $x$. S says "I know your number".
He knows that F has $12$ because he has $6$. These two numbers are the only ones to give $6^12$ in $G_1$.
To be better explained (with a table)...