Java 5 The problem of peach __java

Source: Internet
Author: User

Recently saw such a problem, there are a pile of peach total unknown, there are 5 monkeys. In the morning a monkey came to the peach before the average divided into 5 but one more, the more one ate and then took away one of the remaining four. The second monkey came and divided the remaining peaches into 5 parts. One more to eat and then take away one of the remaining four. The third one ... Every monkey does the same. Ask this pile of peaches at least how many.


Write your own hand for reference only, if there are problems and improve the look left to improve the method



public static void Main (string[] args) {
Star ();
}


public static int star () {
int a = 1; Suppose the last time you divide it into a
int i = 6; The last time the peach was divided into 6 total
int b = 5; Record Count Reverse This is the 5th monkey.

while (true) {
if (5*i%4==0) {///The total number of the previous peach count is a positive integer
i=5*i/4+1; Get the last number of peaches
b--; Number is the last time
System.out.println ("=========" +b);
System.out.println (i);
}else{//To determine whether the previous number of peach count is a positive integer is not a positive integer from new to a value plus 1 set the last time to divide the draw number plus 1
a++; A value plus 1 for the last time to divide the draw number plus 1
i=5*a+1;//so the last time the number of peaches will be calculated from the new
b=5; Times starting from 5
}
if (b==1) {//when the number of 1 o'clock represents 5 can be divided to determine the starting total
Break
}
}
return i; Return the result at least I
}

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.