Print the prime factorization of the greatest common divisor of two numbers Title says it all. Two input 32-bit positive integers m, n &gt;= 2, output gcd(m,n) in prime factorization form.
Input
Command line args or 1 line of stdin okay, whatever's better for golf.
Output
Single space delimited with exponents (no additional spaces). Output nothing if the inputs are relatively prime.
Examples:
$ ./factorize 96 162
2^1 3^1

$ ./factorize 14 15


$ ./factorize 196 294
2^1 7^2

Rules

You may not use external resources, math libraries or built-in functions for factorization or GCD. Examples: Java, no java.lang.Math. ruby, no prime_division, perl, no factor, etc.
Python 3, 255 250  237 226 188 180 150 142 137 136 chars
a,b=map(int,input().split())
t,g='',1
while g&lt;a:
 g,p=g+1,0
 if a%g+b%g&lt;1:
  while a%g+b%g&lt;1:a/=g;b/=g;p+=1
  t+='%d^%d '%(g,p)
print(t)

It's amazing how much I could shorten this by just skipping stuff (like, you know, finding the gcd)! Also I could reduce 10 more chars by making this a function that expects 2 ints, like some other answers, instead of reading from stdin.