Solution to PRIME1 problem spoj.pl