约瑟夫环

Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int num=0;
        for (int i = 2; i <= n; i++) {
            num=(num + m ) % i;
         }
        System.out.println(num+1);

您可能还喜欢...