Guest User

Untitled

a guest
Feb 6th, 2019
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.93 KB | None | 0 0
  1. import java.util.*;
  2. public class S1 {
  3.     static int[] a;
  4.     public static void main(String[] args) {
  5.         Scanner s = new Scanner(System.in);
  6.         int a1 = s.nextInt();
  7.         a = new int[a1];
  8.         int a2 = s.nextInt();
  9.         for(int i = 0; i < a.length; i++)
  10.             a[i] = i + 1;
  11.         for(int i = 0; i < a2; i++) {
  12.             int r = s.nextInt();
  13.             for(int j = 1; j <= a.length; j++) {
  14.                 if(j % r == 0) a[j-1] = 0;
  15.             }
  16.             reset();
  17.         }
  18.         print();
  19.  
  20.     }
  21.     static void print() {
  22.         for(int a : a) {
  23.             if(a != 0) System.out.println(a);
  24.         }
  25.     }
  26.     static void reset() {
  27.         for(int i =0; i < a.length; i++) {
  28.             if(a[i] == 0) {
  29.                 for(int j = i; j < a.length - 1; j++) {
  30.                     a[j] = a[j+1];
  31.                 }
  32.                 a[a.length - 1] = 0;
  33.             }
  34.         }
  35.     }
  36. }
Add Comment
Please, Sign In to add comment