5 Monkeys picked up a pile of peaches and made an appointment early the next morning. The first monkey came early, it will be the peach flat into 5 piles, more than 1, it put out of one to eat, to belong to their own a bunch of take away, will be the rest of the mix a pile, the other monkeys came exactly the same way to deal with.
Program to find out how many peaches are at least. (using recursive functions.) )
here is the recursive algorithm I wrote:
public class Peachdividealgorithm {
private static int num;//Peaches total
private static int count;//Monkey Total, also number
of peaches public static int GetResult (int count) {
if (count==0) {return
1;
}
if ((num-1)%5!=0) {
return-1;
}
Num= (num-1) *4/5;
Return GetResult (count-1);
}
public static void Main (string[] args) {
count=5;
for (int i=0;i<10000;i++) {//Peach number in 10000 of the poor lift
num=i;
if (GetResult (count) ==1) {
System.out.println ("The number of the Peach:" +i);}}}
Print results:
The number of the peach:3121
The number of the peach:6246
The number of the peach:9371 |