fork(1) download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. public class Main {
  6. public static void main(String[] args) {
  7. Scanner in = new Scanner(System.in);
  8. int n = in.nextInt(), k = in.nextInt();
  9. ArrayList<Integer> ns = new ArrayList<Integer>(n);
  10. for (int i = 1; i <= n; i++)
  11. ns.add(i);
  12.  
  13. int i = 0, j = 0;
  14. while(n > 1) {
  15. j = (++j) % k;
  16. if(j == 0) {
  17. n--;
  18. ns.remove(i);
  19. } else {
  20. i = (++i) % n;
  21. }
  22. }
  23. System.out.println(ns.get(0));
  24. }
  25. }
Success #stdin #stdout 0.06s 2184192KB
stdin
76 32
stdout
58