#Java - 184 175
Java - 184 175
This is inspired by @Geobits (and a little of @Tal's answer) answer, but enough of it is different that I decided to create my own answer.
class G{public static void main(String[]a){for(Integer i=1,q,n=i.valueOf(a[0]),m=i.valueOf(a[1]);m>=++i;System.out.print(q>0?i+"^"+q+" ":""))for(q=0;n%i+m%i<1;n/=i,m/=i)q++;}}
Ungolfed (sort of) with (human verification) test harness:
class G {
public static void mainMethod(String[] a) {
for (Integer i = 1, q, n = i.valueOf(a[0]), m = i.valueOf(a[1]); m >= ++i;
System.out.print(q > 0 ? i + "^" + q + " " : ""))
for (q = 0; n % i + m % i < 1; n /= i, m /= i)
q++;
}
public static void main(String[] a) {
m(3, 3);
m(196, 294);
m(294, 196);
m(14, 15);
m(15, 14);
m(96, 162);
m(162, 96);
m(300, 400);
m(400, 300);
m(100, 100);
m(7, 7);
m(4, 8);
}
public static void m(int one, int two) {
mainMethod(new String[] { String.valueOf(one), String.valueOf(two) });
System.out.println();
}
}