I'm not a big fan of the duplication here (line 85), but reading from stdin leaves a newline at the end. I suppose I could extract the match and print_factors though...