I am having some trouble with one of my sample input values, everything else here is working correctly besides the last input.
The problem is to find how many different combinations of $2,$5, and $10 bills can make up the value, here are the sample input and output numbers.
Also in this problem, (2+5) and (5+2) are being treated as unique combinations.
1 - 0
2 - 1
7 - 2
50 - 52524
I am getting the correct answer for everything else, but 52271 for 50, and can't seem to figure out why. Here is my code.
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
long long permutate(long long bill);
long long calculatePossibleOrders(long long A, long long B, long long C);
long long factor(long long x);
int main()
{
long long num_cases, i;
/* code for grabbing c - number of cases to solve */
scanf("%I64d", &num_cases);
/* for loop for each case */
for(i = 0; i < num_cases; i++)
{
long long bill = 0;
scanf("%I64d", &bill);
printf("%I64d\n", permutate(bill));
}
}
long long permutate(long long bill)
{
long long originalbill = bill;
long long CurrentBill = originalbill;
long long numberofOptions = 0;
long long A, B, C;
if(bill == 1 || bill == 3)
{
return 0;
}
for(A = 0; A <= originalbill; A+=10)
{
B = 0, C = 0;
if((CurrentBill - A) == 0)
{
numberofOptions += calculatePossibleOrders(A, B, C);
break;
}
for(B = 0; (A + B) <= CurrentBill; B+=5)
{
C = 0;
if((CurrentBill - (A + B)) == 0)
{
numberofOptions += calculatePossibleOrders(A, B, C);
break;
}
for(C = 0; (A+B+C) <= CurrentBill; C+=2)
{
if((CurrentBill - (A + B + C)) == 0)
{
numberofOptions += calculatePossibleOrders(A, B, C);
break;
}
}
}
}
return(numberofOptions);
}
long long calculatePossibleOrders(long long A, long long B, long long C)
{
long long combos = 0;
long long x = 0;
if(A > 0)
{
A /= 10;
}
if(B > 0)
{
B /= 5;
}
if(C > 0)
{
C /= 2;
}
x = A+B+C;
combos = factor(x)/(factor(A)*factor(B)*factor(C));
return(combos);
}
long long factor(long long x)
{
long long i;
long long value = 1;
for(i = 1; i <= x; i++)
{
value = value*i;
}
return(value);
}