Untitled

mail@pastecode.io avatar
unknown
java
2 years ago
4.3 kB
2
Indexable
Never
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.regex.*;
import java.util.stream.*;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;

class Result {

    /*
     * Complete the 'maxDias' function below.
     *
     * The function is expected to return an INTEGER.
     * The function accepts following parameters:
     *  1. INTEGER N
     *  2. INTEGER p
     *  3. INTEGER q
     *  4. INTEGER r
     */

    public static int maxDias(int N, int p, int q, int r) {
      

      ArrayList<Integer> pList = new ArrayList<Integer>();
      ArrayList<Integer> qList = new ArrayList<Integer>();
      ArrayList<Integer> rList = new ArrayList<Integer>();
      
      for(int j = 1; j <=N; j++){
          pList.add(p*j);
          qList.add(q*j);
          rList.add(r*j);
      }
      
      for(int a = 0; a < pList.size();a++){
        
        for(int b=0; b < qList.size();b++){
          if(pList.get(a)==qList.get(b)){
            for(int d = 0; d < rList.size(); d++){
              if(qList.get(b)==rList.get(d)){
                rList.remove(d);
              }
            }
            pList.remove(a);
            qList.remove(b);
          }
          if(pList.get(a)==rList.get(b)){
            for(int e = 0; e < rList.size(); e++){
              if(rList.get(b)==qList.get(e)){
                qList.remove(e);
              }
            }
            pList.remove(a);
            rList.remove(b);
          }
        }
      }
      for(int a = 0; a < rList.size();a++){
        
        for(int b=0; b < pList.size();b++){
          if(rList.get(a)==pList.get(b)){
            for(int d = 0; d < qList.size(); d++){
              if(pList.get(b)==qList.get(d)){
                qList.remove(d);
              }
            }
            rList.remove(a);
            pList.remove(b);
          }
          if(rList.get(a)==qList.get(b)){
            for(int e = 0; e < qList.size(); e++){
              if(qList.get(b)==pList.get(e)){
                pList.remove(e);
              }
            }
            pList.remove(a);
            qList.remove(b);
          }
        }
      }
      for(int a = 0; a < qList.size();a++){
        
        for(int b=0; b < rList.size();b++){
          if(qList.get(a)==rList.get(b)){
            for(int d = 0; d < pList.size(); d++){
              if(rList.get(b)==pList.get(d)){
                pList.remove(d);
              }
            }
            qList.remove(a);
            rList.remove(b);
          }
          if(qList.get(a)==pList.get(b)){
            for(int e = 0; e < pList.size(); e++){
              if(pList.get(b)==rList.get(e)){
                rList.remove(e);
              }
            }
            rList.remove(a);
            pList.remove(b);
          }
        }
      }
      return (pList.size()+ qList.size()+rList.size());
}

public class Solution {
    public static void main(String[] args) throws IOException {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(System.out));

        int T = Integer.parseInt(bufferedReader.readLine().trim());

        IntStream.range(0, T).forEach(TItr -> {
            try {
                String[] firstMultipleInput = bufferedReader.readLine().replaceAll("\\s+$", "").split(" ");

                int dias = Integer.parseInt(firstMultipleInput[0]);

                int A = Integer.parseInt(firstMultipleInput[1]);

                int B = Integer.parseInt(firstMultipleInput[2]);

                int C = Integer.parseInt(firstMultipleInput[3]);

                int resultado = Result.maxDias(dias, A, B, C);

                bufferedWriter.write(String.valueOf(resultado));
                bufferedWriter.newLine();
            } catch (IOException ex) {
                throw new RuntimeException(ex);
            }
        });

        bufferedReader.close();
        bufferedWriter.close();
    }
}