You need to find the least common multiples of both numbers.
The least (first) common multiple is 40.
10 x 4 = 40, hence you would need 4 boxes of ramen.
8 x 5 = 40, so you would need 5 boxes of rice.
To do this, basically all you need to do is find the lowest common multiple of 10 and 8, and find 8 times what is 40, and 10 times what is 40.
Hope this helps! :)