Google-code-jam-Qualification-2011---Magicka is a project mainly written in Java, it's free.
http://code.google.com/codejam/contest/dashboard?c=975485#s=p1
works for both small and large inputs.