C Language Examples - Five People Dividing Fish
A, B, C, D, and E went fishing together one night. By early the next morning 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 extra one fish, and took his own portion.
B woke up second, also divided the fish into five portions, threw away the extra one and took his own portion. .
C, D, and E woke up in turn and took fish in the same way.
Ask at least how many fish they caught together, and how many fish each person saw when they woke up?
Example
#include
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 %d fish caught together\n"
,n
)
;
printf
(
"Number of fish each saw: %d %d %d %d\n"
,j,k,l,m
)
;
break
;
}
}
return
0
;
}
The output of the above example is:
至少合伙捕鱼:3121条
分别见到鱼的条数:2496 1996 1596 1276
C Language Examples