The five hundred silver pennies might have been
placed in the
four bags,
in accordance with the stated conditions, in exactly 894,348 different
ways.

If there had been a thousand coins there would be
7,049,112 ways.
It is a difficult problem in the partition of numbers.

I have a single
formula for the solution of any number of coins in the case of four
bags,
but it was extremely hard to construct, and the best method is to find
the twelve separate formulas for the different congruences to the
modulus
12.