C Language Example - Five People Dividing Fish
Five people, A, B, C, D, and E, went fishing together one night. By early morning the next day they were all exhausted, so each found a place to sleep.
When the sun was high, A woke up first. He divided the fish into five portions, threw away the one extra fish, and took his own share.
B woke up second, also divided the fish into five portions, threw away the one extra fish, and took his own share.
C, D, and E woke up in turn and took fish in the same way.
The question is: how many fish did they catch at least altogether? And how many fish did each person see when waking up?
Example
#include <stdio.h>
int main(){
int n,x,j,k,l,m;
for(n=5;;n++){
j=4*(n-1)/5;
k=4*(j-1)/5;
l=4*(k-1)/5;
m=4*(l-1)/5;
if(n%5==1&&j%5==1&&k%5==1&&l%5==1&&m%5==1){
printf("At least jointly caught fish: %d fish\n",n);
printf("The number of fish seen respectively: %d %d %d %d\n",j,k,l,m);
break;
}
}
return 0;
}
int main(){
int n,x,j,k,l,m;
for(n=5;;n++){
j=4*(n-1)/5;
k=4*(j-1)/5;
l=4*(k-1)/5;
m=4*(l-1)/5;
if(n%5==1&&j%5==1&&k%5==1&&l%5==1&&m%5==1){
printf("At least jointly caught fish: %d fish\n",n);
printf("The number of fish seen respectively: %d %d %d %d\n",j,k,l,m);
break;
}
}
return 0;
}
The output result of the above example is:
至少合伙捕鱼:3121条 分别见到鱼的条数:2496 1996 1596 1276other extensions