Quantum Algorithms and Circuits for Linear Equations with Infinite or No Solutions