Solution of a problem of Ulam