title: Math for Buy X Get Y For Z
body: <p>I'm working on a POS software that require a Buy X Get Y For Z discount schema, i.e: Buy 5 Get 2 For 5$, it means if you buy 7 items, 5 items are normal price and 2 items (6th, 7th) are 5$.</p>
  
  <p>This is the spreadsheet for this <a href="https://docs.google.com/spreadsheets/d/1ym93Xqnw6wupBEp9ei711wQPpt3s6QONjcqBO4Xc5X4/edit#gid=0" rel="nofollow">https://docs.google.com/spreadsheets/d/1ym93Xqnw6wupBEp9ei711wQPpt3s6QONjcqBO4Xc5X4/edit#gid=0</a></p>
  
  <p>I want to a algorithm to get X and Y (discounted item) when input quantity</p>
  
  <p>i.e: input quantity and it will return X and Y for Buy 5 Get 2</p>
  
  <pre><code>input 7 return X = 5, Y= 2
  
  input 8 return X = 6, Y= 2
  ..
  
  input 17 return X= 13,Y= 4
  </code></pre>
  
  <p>I'm trying to find formula for this one but I'm failed. Please help me thanks</p>