Sale of goldfish
The buyer and seller sold the goldfish in a tank for five times. The last time the system sold half of the whole, it added 1/2; the second time it sold the remaining 1/3 and 1/3; for the third time, the remaining 1/4 and 1/4 items are sold. for the fourth time, the remaining 1/5 and 1/5 items are sold. For the last time, the remaining 11 items are sold. How many goldfish are there in the original fish tank?
* Question analysis and Algorithm Design
All the fish in the question are sold for five times, and the strategy for each sale is the same; the remaining (J + 1) points of the second (J + 1) are repeatedly added with 1/(J + 1. In the fifth round, we sold all the remaining 11 items for the fourth round.
Assuming that the total number of times J fish is X, the J fish is left:
X-(x + 1)/(J + 1)
When the fourth sale is complete, there should be 11 remaining items. If X meets the preceding requirements, X is the solution of the question.
Note that "(x + 1)/(J + 1)" must meet the division criteria. The initial value of test X can start from 23, and the test step is 2, because the value of X must be an odd number.
* Program Description and comment
# Include <stdio. h>
Void main ()
{
Int I, j, n = 0, x;/* n is the flag variable */
For (I = 23; n = 0; I + = 2)/* control the test step and process */
{
For (j = 1, x = I; j <= 4 & x> = 11; j ++)/* four sales operations */
If (x + 1) % (J + 1) = 0)/* If the Division conditions are met, the actual sales operation is performed */
X-= (x + 1)/(J + 1 );
Else {x = 0; break;}/* otherwise, the computing process is stopped */
If (j = 5 & X = 11)/* If the remaining 11 items in the fourth time meet the question */
{
Printf ("there are % d fishes at first. N", I);/* output result */
N = 1;/* control the exit test process */
}
}
}
* Running result
There are 59 fishes at first.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.