You may be getting 0's from integer division. But I think the formula above is off for what you're trying to achieve.
If you enter 650 as x, that would be one 500 bill, one 100 bill and one 50 bill.
650 % 500 is going to be 150. That's the amount left after you account for one 500 bill, not the number of 500 bills.