When the polynomial f(x) is divided by x^3 + x + 1, the remainder is 3. When the polynomial f(x) is divided by x^2 + 1, the remainder is x + 1. Find the remainder when f(x) is divided by x.