Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.math.BigInteger;
- import java.util.*;
- public class Problem3 {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- String input = sc.nextLine();
- ArrayList<ArrayList<Long>> nums = new ArrayList<>();
- ArrayList<Long> formulas = new ArrayList<>();
- boolean criticalPointFound = false;
- BigInteger lines = BigInteger.valueOf(0);
- while (!input.equals("Break it.")) {
- String[] numbers = input.split(" ");
- long firstN = Integer.parseInt(numbers[0]);
- long secondN = Integer.parseInt(numbers[1]);
- long thirdN = Integer.parseInt(numbers[2]);
- long fourthN = Integer.parseInt(numbers[3]);
- long[] numbersArray = {firstN, secondN, thirdN, fourthN};
- ArrayList<Long> numbersList = new ArrayList<>();
- for(int i =0 ;i < 4;i++){
- numbersList.add(numbersArray[i]);
- }
- long formula = Math.abs((fourthN + thirdN) - (firstN + secondN));
- formulas.add(formula);
- nums.add(numbersList);
- lines = lines.add(BigInteger.valueOf(1));
- input = sc.nextLine();
- }
- BigInteger criticalpointValue = BigInteger.valueOf(0);
- HashSet<Long> hashFormulas= new HashSet<>(formulas);
- if(hashFormulas.size()<=2){
- criticalPointFound =true;
- if (!hashFormulas.contains(0L)){
- criticalPointFound= false;
- }
- if(hashFormulas.size()==1){
- criticalPointFound=true;
- }
- }
- for(Long formula : hashFormulas){
- if(formula!=0){
- criticalpointValue = BigInteger.valueOf(formula);
- }
- }
- int linesInt = lines.intValue();
- if (criticalPointFound) {
- for (ArrayList<Long> line: nums) {
- System.out.println("Line: " + line);
- }
- BigInteger power = criticalpointValue.pow(linesInt);
- BigInteger criticalbreakpoint = power.remainder(lines);
- System.out.printf("Critical Breakpoint: %d\n", criticalbreakpoint);
- } else {
- System.out.println("Critical breakpoint does not exist.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment