SPOJ - Fun with numbers