About five minutes monkeys bananas

       There are five monkeys found a bunch of bananas at the beach and decided to split the next day, the next morning, the first monkey first came, it left and right sub-divided inseparable, he threw a toward the sea, just be divided into five parts, it takes on their part to go. 2,3,4,5 monkeys also encountered the same problem, using the same method, are thrown away after one, it happens to be divided into five parts, ask this pile of bananas at least less only?

method one

class Untitled {
    public static void main(String[] args) {
        int number;
        int count = 0;
        int i;
        for(i=6 ;;i=i+5){
            number = i;
            count = 0;
            while((number - 1) % 5 == 0){
                count++;
                number = (number -1) / 5 * 4;
                if(count == 5){
                    break;
                }
            }
            if(count == 5){
                break;
            }
        }
        System.out.println(i);
    }
}

Second way 

class Untitled {
     public  static  void main (String [] args) { 
        System.out.println ( "minimum on the beach" + count () + "banana" ); 
    } 

    public  static  int COUNT () {
         // n-number of representatives , k 1 representative of each dispensing parts
         int n-=. 5, k = 1, min = 0 ;
         Boolean in Flag = to false ; 
// j represents a number of banana after the last allocation of the monkeys
int j = 1 ; for (;; j ++ ) { min = J * + n- K; for ( int I =. 1; I <n-; I ++ ) { if(min % (n-1) == 0){ min = min * n / (n-1) +k; }else{ break; } if(i == n-1){ flag = true; break; } } if(flag == true){ break; } } System.out.println(j); return min; } }

Thrust reversers verification

class Untitled { 

    public  static  void main (String [] args) { 
        System.out.println ( "---------" + (Reverse (3121,5) == 1 "Success":? "Fail" ) + "----------" ); 
    } 

    public  static  int Reverse ( int n-, int m) {
         // after each take the remaining NUM 
        int NUM = n--. 1 - (n--. 1) / 5 ; 
        m - ;
         IF (m> 0 ) {
             // each take bananas can be divisible by 5 
            IF ((n--. 1) 5% == 0 ) {
                 return  Reverse (NUM, m);
            } the else {
                return 0;
            }
        } else {
            return 1;
        }
    }
}

At least 3121 bananas, thinking: The Backward Pass.
Set points next day each monkey a banana
5a * (5/4) +1: There prior to the fifty monkeys not take
until the fourth monkey did not take there: 5a * (5/4) ² + 5/4 + 1
has not take before the third monkey: 5a * (5/4) ³ + (5/4) ² + 5/4 + 1
second monkey have not previously take: 5a * (5/4) ^ 4 + (5/4) ³ + (5/4) ² + 5/4 + 1
has not take before the first monkey: 5a * (5/4) +. 5 ^ (5/4) +. 4 ^ (5/4) ³ + (5/4) ². 5 + / +. 1. 4 ·········· ①
① 5 is a rear formula geometric series , there summation: 5a * (5/4) ^ 5 + 4 * (5/4) ^ 5-4 = (5a + 4) * (5/4) ^ 5-4 = min
followed for the minimum min , so 5a + 4 = 4 ^ 5, solve for a = 204, that was brought min = 3121.

Guess you like

Origin www.cnblogs.com/rinack/p/11069113.html