【编程题解】Game of Throne

Description

After the death of DaenerysStormborn of the House Targaryen, the First of Her Name, the Unburnt, Queen of Meereen, Queen of the Andals and the Rhoynar and the First Men, Khaleesi of theGreat Grass Sea, Breaker of Chains and Mother of Dragons, several leaders decided to play a game to decide who would sit on the Iron Throne,There are n people in acircle, and their ids are 1 ~ n (n is close to 1).

Now counting starts from number1, the person who counted to m in the first round will be out, and the second round will start counting from the next person and the person who countedto m^2 will be out.

And so on, until the person who counted to m^（n−1）in the last round is out, leaving the last one.

Output the number of this person.

Input

One line, containing two integersn and m.

Data range：n≤15, m≤5n≤15, m≤5

Output

Output the number of the lastperson who is left.

Sample Input 1

5 2

Sample Output 1

5

Personal Answer  (using language：JAVA)  Not necessarily right

import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int m = scanner.nextInt();

int [] array = new int[n];
for(int i=0;i<n;i++){
array[i]=i+1;
}

List<Integer> list = Arrays.stream(array).boxed().collect(Collectors.toList());

int delete_num = m;
int times=0;
int start_num=0;
times++;
delete_num=(int)Math.pow(m,times);
start_num=tmp;
}

}
}

Welcome to communicate!

03-21 5787
05-18 6115

06-11 6762
09-07 6522
09-06 2万+
06-04 1148
03-21 1862
05-09 2274
09-07 8720
08-31 1万+