I implemented the quadratic sieve in Haskell according to the basic algorithm specified on the Wikipedia page. It works great on most integers, however it fails to find a factorization on numbers N that are nth powers. For even powers (squares), the algorithm loops, and for odd powers I find several smooth numbers that are squares mod N (I have tested and confirmed this), yet every single derived congruence of squares (also tested and confirmed) leads only to a trivial factor.
I am reasonably sure that I implemented the Wikipedia algorithm to the letter. Is there a problem with that version of the algorithm that prevents it from handling nth powers, or is there a bug in my algorithm?
For some reason stackoverflow is having an issue formatting my code, so here you go: http://pastebin.com/miUxHKCh