Problem #3 Solved

It's a little bit dirty, because I wanted to solve assuming no additional prior knowledge in number theory nor requiring additional gems/files, but it works quickly and like a charm.