Are you by any chance using Herbert Enderton’s textELEMENTS OF SET THEORY?

If so, this problem appears in it with a nice theorem about functioncompatible with equivalence relations.

If not, here is the basic idea. Consider the function .

It should be clear to you that if have the same number of prime factor then so do .

In other words, this is enough to say is compatible with .

Thus there exists .

If you need details your library should a copy of that text.