problem 1048 (improved)