import java.io.*;
import java.util.Scanner;
class Main {
Â
  static int soldiers(int N, int K)
  {
    if (N == 1)
      return 1;
    else
      return (soldiers(N - 1, K) + K - 1) % N + 1;
  }
  public static void main(String[] args)
  {
    Scanner input=new Scanner(System.in);
    System.out.println("Number of soldiers in the enemy camp")
    int N = input.nextInt();
    System.out.println("Number of soldiers to be killed")
    int K = input.nextInt();
    System.out.println(soldiers(N, K));
  }
}
Comments
Leave a comment