Five monkeys picked a bunch of peaches together, because they were too tired, they decided to go to sleep and then divide. One of the monkeys came, it saw other monkeys did not come, then the pile of peaches evenly divided into 5 pieces, the result of one more, will eat more of this, and take away one of them. For a moment, the first 2 monkeys came, he did not know that already had a companion, thought he was the first to come, so the peach piled up on the ground, and then an average of 5, found that there is one more, the same ate the 1, and took one of them. The next 3, 4 and 5 monkeys are doing the same thing ... According to the above conditions, ask these 5 monkeys to pick at least how many peaches ? The number of Peaches left after the first 5 monkeys left ?
Enumeration method: It is very significant to find the enumeration object to improve the efficiency of enumeration, enumerate the S0, and the efficiency of enumeration S5. S0 executed 3,116 times, while S5 performed only 255 times.
#include <stdio.h>intMain () {intS0,s1,s2,s3,s4,s5,n,i; for(s5=1;; s5++) {S4=5*s5+1; if(s4%4) Continue; ElseS4/=4; S3=5*s4+1; if(s3%4) Continue; ElseS3/=4; S2=5*s3+1; if(s2%4) Continue; ElseS2/=4; S1=5*s2+1; if(s1%4) Continue; ElseS1/=4; S0=s1*5+1; Break; } printf ("%d%d\n", s0,s5*4); return 0;}
The monkey picks the Peach