Advertisement
SotirovG

MathPotato_07_St&Qu

Apr 22nd, 2021
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.18 KB | None | 0 0
  1. package JavaProModule.JavaAdvanced.StackAndQueuesLab;
  2.  
  3. import java.util.ArrayDeque;
  4. import java.util.Collections;
  5. import java.util.Deque;
  6. import java.util.Scanner;
  7.  
  8. public class MathPotato_07 {
  9.     public static void main(String[] args) {
  10.         Scanner read = new Scanner(System.in);
  11.  
  12.         String[] children = read.nextLine().split("\\s+");
  13.         Deque<String> players = new ArrayDeque<>();
  14.         Collections.addAll(players, children);
  15.         int loop = Integer.parseInt(read.nextLine());
  16.  
  17.         int cycle = 1;
  18.         boolean isPrime = false;
  19.  
  20.  
  21.         while (players.size() > 1) {
  22.             cycle++;
  23.  
  24.             for (int index = 1; index < loop; index++) {
  25.                 players.offer(players.poll());
  26.             for (int i = 2; i <= cycle / 2; i++) {
  27.                 if (cycle % i == 0) {
  28.                     isPrime = true;
  29.                 }
  30.  
  31.             }
  32.             if (isPrime) {
  33.                 System.out.println("Prime" + players.peek());
  34.             } else {
  35.  
  36.                 System.out.println("Removed " + players.poll());
  37.             }
  38.  
  39.  
  40.             }
  41.             System.out.println("Last is " + players.poll());
  42.         }
  43.  
  44.  
  45.     }
  46. }
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement