finding out what two numbers go into a number with no remainder.

I'm trying to make a program that will try to find two perfect square numbers(4, 9, 16, etc)(x, and y) that go into another number(z) with no remainder, then try to square root x and y as far as they go, while still being a whole number. for example, if I enter 32, if will see that 16 and 2 go into 32 evenly, and that 16 can be square rooted to 4, and 4 to 2. but won't except, for example, 8 and for, because 8 can't be square rooted evenly. I have an idea where to go with this, like check to see if all the perfect squares multiplyed together equaled the number, but there's got to be an easyer algorythem then 1000+ if statements. if anyone has any ideas or links on where to go with this, I'd appreciate it alot, thanks.