JavaScript (ECMAScript 6 Draft) - 89 Characters
f=(m,n,i=2,k=0)=>(m%i|n%i?(k?i+'^'+k+' ':'')+(i>m?'':f(m,n,i+1)):f(m/i,n/i,i,k+1)).trim()
Converts the original (iterative) answer, below, into a recursive one.
Explanation
f=(m,n,i=2,k=0)=> // A function with arguments m and n and optional arguments
// i (defaults to 2) and k (defaults to 0)
(
m%i|n%i // if i is not a divisor of m or n then:
?(k?i+'^'+k+' ' // if k is non-zero append "i^k " to the output
:'') // else append nothing
+(i>m?'' // if i>m then terminate
:f(m,n,i+1)) // else increment i and reset k to 0
:f(m/i,n/i,i,k+1) // else divide m and n by i and increment k
).trim() // finally strip any extra spaces from the output.
Iterative Answer: JavaScript (ECMASCript 6) - 108 (or 121) 98 Characters
Version 2:
f=(m,n)=>{for(s='',i=1;++i<=m;s+=k?' '+i+'^'+k:'')for(k=0;m%i+n%i<1;k++)m/=i,n/=i;return s.trim()}
Version 1:
Answering the question as originally asked:
f=(m,n)=>{for(o=[],i=2;i<=m;)m%i|n%i?i++:(m/=i,n/=i,o[i]=(o[i]|0)+1);return o.map((x,i)=>i+"^"+x).join(' ')}
Or to comply with the rule changes after the fact:
f=(m,n)=>{for(o=[],i=2;i<=m;)m%i|n%i?i++:(m/=i,n/=i,o[i]=(o[i]|0)+1);return o.map((x,i)=>i+"^"+x).filter(x=>x).join(' ')}
Explanation
f=(m,n)=> // Create a function f with arguments m and n
{
o=[] // Initialise an empty array for the output
i=2 // Start with a divisor of 2
for(;i<=m;) // Loop while the divisor is not greater than m
m%i|n%i // Test the bitwise OR of m%i and n%1 (i.e. whether
// at least one is non-zero)
?i++ // If m%i>0 or n%i>0 then increment i
:(m/=i, // Otherwise: divide m by i;
n/=i, // n by i;
o[i]=(o[i]|0)+1); // and add 1 to the i-th element of o
return o.map((x,i)=>i+"^"+x) // finally map the sparse array o to a sparse array
// of the strings (index+"^"+value)
.filter(x=>x) // turn sparse array into non-sparse array
.join(' ') // then concatenate and return.
}
Output
f(96,162)
"2^1 3^1"
f(14,15)
""
f(80, 80)
"2^4 5^1"
f(196,294)
"2^1 7^2"
gcd(n,m) == 1
? \$\endgroup\$q:a+.b
or__ q:a+.b
in J uses noexternal resources or math libraries
, but I won't post it, since it's too far from the spirit of the question. I just thought I'd share it here. \$\endgroup\$