zoukankan      html  css  js  c++  java
  • 华为猴子吃桃子问题

    N(3<=N<=9))只猴子采得一堆桃子,半夜里第一只猴子偷偷起来把桃平均分成N分, 发现还多一个,它吃了那个桃子,还拿走其中的一份,第二只猴子起来又把桃子分成N分,还多一个,它吃了那个桃子,又拿走其中的一份,第三只、第四只......第N只猴子都如此做了,请问这堆桃子至少有多少个?

    直接上代码:

    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();

     

    }

     

    }

  • 相关阅读:
    Munge
    file upload custom form
    随笔摘要
    生成css 和 清缓存
    drupal commit 原则
    Git reset --hard
    www-data
    301/302的区别
    什么是request_uri
    in_array foreach array_search的性能比较
  • 原文地址:https://www.cnblogs.com/liuchuanwu/p/4781247.html
Copyright © 2011-2022 走看看