Huawei Monkey Eats peach problem

Source: Internet
Author: User

N (3<=n<=9)) only monkeys picked a bunch of peaches, the first monkey secretly up in the middle of the night, the peach evenly divided into n points, found that more than one, it ate the peach, but also take one of them, the second monkey up and put the peach into N points, and one more, it ate the peach, and took one of them, The third and fourth ... The first n monkeys have done so, how many of these peaches are there at least?

Directly on the code:

Package test;

Import Java.util.Scanner;

Public class Monkey {

static int n;

static int sum;

static Scanner Scanner = new Scanner (System. in);

public static void Main (string[] args) {

System. out.println ("" +integer. Max_value);

input ();

output ();

}

Private static void output () {

System. out.println ("" + N);

if (n > 9 | | N < 3) {

System. Out.println ("0");

} else {

int number = n;

For (int i = n + 1; i < Integer. Max_value; i++) {

if (!isok (i, number ))

continue;

else {

System. Out.println ("" + i);

Break ;

}

}

}

}

Private static boolean isOk (int i, int m) {

int count = 0;

While (count < m) {

if (i% (m)! = 1)

return false;

i = i-1-(I/ m);

count++;

}

return true;

}

Private static void input () {

n = scanner.nextint ();

}

}

Huawei Monkey Eats peach problem

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.