Solve problem 31 using Rust.