So n must not be prime. Then n is composite, so it has some number of prime factors, we'll denote this number with f.
then n =
which simplifies to
Because the greatest common denominator of a and b is 1, they cannot share common factors, and thus whichever prime factors of n are elements in a, they cannot be elements in b, and therefore their adjoining value must also be in the same group, for example if n_1 is in a, then it cannot be in b, and so both n_1's must be in a. Which means that is part of a's factorization. This holds true for all f prime factors of n.
Let the elements in a be denoted with c, and the elements in b be denoted with d, then a = c^2 and c is the product of some selection from the set of prime factors of n. And b = d^2 with d being the product of the remaining prime factors of n.
let cf be the f'th factor of n in the group c, and df be the same for d