how to calculate the number of certain size picture/paper into one larger paper...

for example 2"x4" size paper/picture wanted to fit into to 8"x10"

how many size of 2"x4" can fit into a 8"x10"

is there a solution that will work for all different sizes?

Any help is highly appreciated... Thanks