Guest User

Untitled

a guest
Apr 25th, 2016
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.30 KB | None | 0 0
  1. import java.math.BigInteger;
  2. import java.util.*;
  3.  
  4. public class Problem3 {
  5.     public static void main(String[] args) {
  6.  
  7.         Scanner sc = new Scanner(System.in);
  8.         String input = sc.nextLine();
  9.         ArrayList<ArrayList<Long>> nums = new ArrayList<>();
  10.         ArrayList<Long> formulas = new ArrayList<>();
  11.         boolean criticalPointFound = false;
  12.         BigInteger lines = BigInteger.valueOf(0);
  13.         while (!input.equals("Break it.")) {
  14.             String[] numbers = input.split(" ");
  15.             long firstN = Integer.parseInt(numbers[0]);
  16.             long secondN = Integer.parseInt(numbers[1]);
  17.             long thirdN = Integer.parseInt(numbers[2]);
  18.             long fourthN = Integer.parseInt(numbers[3]);
  19.             long[] numbersArray = {firstN, secondN, thirdN, fourthN};
  20.             ArrayList<Long> numbersList = new ArrayList<>();
  21.             for(int i =0 ;i < 4;i++){
  22.                 numbersList.add(numbersArray[i]);
  23.             }
  24.             long formula = Math.abs((fourthN + thirdN) - (firstN + secondN));
  25.             formulas.add(formula);
  26.             nums.add(numbersList);
  27.            lines = lines.add(BigInteger.valueOf(1));
  28.             input = sc.nextLine();
  29.         }
  30.         BigInteger criticalpointValue = BigInteger.valueOf(0);
  31.         HashSet<Long> hashFormulas= new HashSet<>(formulas);
  32.         if(hashFormulas.size()<=2){
  33.             criticalPointFound =true;
  34.             if (!hashFormulas.contains(0L)){
  35.                 criticalPointFound= false;
  36.             }
  37.             if(hashFormulas.size()==1){
  38.                 criticalPointFound=true;
  39.             }
  40.         }
  41.         for(Long formula : hashFormulas){
  42.             if(formula!=0){
  43.                 criticalpointValue = BigInteger.valueOf(formula);
  44.             }
  45.         }
  46.         int linesInt = lines.intValue();
  47.         if (criticalPointFound) {
  48.             for (ArrayList<Long> line: nums) {
  49.                 System.out.println("Line: " + line);
  50.             }
  51.                 BigInteger power = criticalpointValue.pow(linesInt);
  52.                 BigInteger criticalbreakpoint = power.remainder(lines);
  53.                 System.out.printf("Critical Breakpoint: %d\n", criticalbreakpoint);
  54.  
  55.         } else {
  56.             System.out.println("Critical breakpoint does not exist.");
  57.         }
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment