A famous furniture store staged a big sale of chairs which attracted numerous customers.
The 1st customer bought 2 chairs plus a half of the remaining chairs.
The 2nd customer bought 3 chairs plus a third of the remaining chairs.
The 3rd customer bought 4 chairs plus a quarter of the remaining chairs
... etc till it was impossible to proceed in the said manner.
How many customers could be accommodated and how many chairs were sold to them?
It's to be assumed that indeed at least 3 customers were served.
Let n be the number of chairs in stock at the beginning.
After the first customer left, (n2)/2 chairs were left.
After the second customer left, (n8)/3 chairs were left.
After the third customer left, (n20)/4 chairs were left.
After the fourth customer would have left, (n40)/5 chairs would have been left.
After the fifth customer would have left, (n70)/6 chairs would have been left.
The first formula above requires n to be even.
The second requires n to be 2 more than a multiple of 3.
The third requires n to be a multiple of 4.
The fourth requires n to be a multiple of 5.
The fifth would require n to be 4 more than a multiple of 6 and therefore 1 more than a multiple of 3, which is incompatible with the remaining chairs after customer 2.
Therefore only 3 or 4 customers were accommodated.
Depending on the exact numbers of chairs originally in stock, differing numbers of chairs had been sold:
n customers chairs sold
20 3 20
32 3 29
44 3 38
56 3 47
68 3 56
80 4 72
92 3 74
104 3 83
116 3 92
128 3 101
140 4 120
152 3 119
164 3 128
176 3 137
188 3 146
200 4 168
212 3 164
224 3 173
236 3 182
248 3 191
260 4 216
272 3 209
284 3 218
296 3 227
308 3 236
320 4 264
332 3 254
344 3 263
356 3 272
368 3 281
380 4 312
392 3 299
404 3 308
416 3 317
428 3 326
440 4 360
452 3 344
464 3 353
476 3 362
488 3 371
500 4 408
For n = 8 To 500 Step 12
remain = n
For cust = 1 To 10000
saveremain = remain
remain = remain  (cust + 1)
If remain Mod (cust + 1) = 0 And remain >= 0 Then
remain = remain  remain / (cust + 1)
Else
Exit For
End If
Next cust
If cust  1 >= 3 Then
Text1.Text = Text1.Text & mform(n, "###") & mform(cust  1, "#######0") & mform(n  saveremain, "############0") & crlf
DoEvents
End If
Next

Posted by Charlie
on 20141031 10:19:44 