Moved factorize to a separate class. 50 on Kattis.