Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
3.4 kB
1
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 Result1 {

    /*
     * 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) {
        int pi=0;
        int qi=0;
        int ri=0;
        if (p==q && p==r){
            return 0;
        }
        int paux=0,qaux=0,raux=0;
        for(int i=1; i<=N; i++){
            if(p*i<=N){
                paux=(p*i);
                pi++;
            }
            if(q*i<=N){
                qaux=(q*i);
                qi++;
            }
            if(r*i<=N){
                raux=(r*i);
                ri++;
            }
        }

        if(q==r && p>r){
            System.out.println(1);
            return (pi%qi+pi%ri);
        }
        if(p==q && r>p){
            System.out.println(2);
            return (ri%pi+ri%qi);
        }
        if(p==r && q>p){
            System.out.println(3);
            return (qi%pi+qi%ri);
        }
        if (p>q && q>r){
            System.out.println(4);
            return (pi%qi+pi%ri);
        }
        if (p<q && q<r){
            System.out.println(5);
            return (ri%pi+ri%qi);
        }
        if (p<q && p<r){
            System.out.println(6);
            return (qi%pi+qi%ri);
        }
        /*System.out.println(paux);
        System.out.println(qaux);
        System.out.println(raux);
        System.out.println(p%q);
        System.out.println(p%r);
        System.out.println(q%p);
        System.out.println(q%r);
        System.out.println(r%p);
        System.out.println(r%q);*/
        System.out.println("default");
        return (pi%qi+pi%ri);
    }

}

public class TareaEdaAeropuerto {
    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 = Result1.maxDias(dias, A, B, C);

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

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