Help in no change

denoting greater denomination by d2 and smaller by d1
when p % d2 = 0 and p%d1 = 0 and d2%d1 != 0
int x = p/d2 - 1;
will printing the following answer work
no. of coins of denomination d2 = x;
no. of coins of denomination d1 = x/d1 + 1;

my code gives sigfpe