Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.ArrayList;
- public class Main
- {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int first = Integer.parseInt(sc.nextLine());
- int second = Integer.parseInt(sc.nextLine());
- int third = Integer.parseInt(sc.nextLine());
- int spiralCurrent = Integer.parseInt(sc.nextLine());
- int spiralIncrease = Integer.parseInt(sc.nextLine());
- ArrayList<Integer> tribonacciNumbers = new ArrayList<>();
- tribonacciNumbers.add(first);
- tribonacciNumbers.add(second);
- tribonacciNumbers.add(third);
- int tribonacciCurrent = third;
- while(tribonacciCurrent < 1000000){
- tribonacciCurrent = first + second + third;
- tribonacciNumbers.add(tribonacciCurrent);
- first = second;
- second = third;
- third = tribonacciCurrent;
- }
- ArrayList<Integer> spiralNumbers = new ArrayList<Integer>();
- spiralNumbers.add(spiralCurrent);
- int spiralCount = 0;
- int spiralStepMul = 1;
- while(spiralCurrent < 1000000){
- spiralCurrent += spiralIncrease * spiralStepMul;
- spiralNumbers.add(spiralCurrent);
- spiralCount++;
- if(spiralCount % 2 == 0){
- spiralStepMul++;
- }
- }
- boolean found = false;
- for(int i =0;i<tribonacciNumbers.size();i++){
- for(int j = 0;j<spiralNumbers.size();j++){
- if(tribonacciNumbers.get(i).equals(spiralNumbers.get(j)) && tribonacciNumbers.get(i) < 10000000){
- System.out.println("Match at number: " + tribonacciNumbers.get(i));
- found = true;
- break;
- }
- }
- if(found){
- break;
- }
- }
- if(!found){
- System.out.println("NO!");
- }
- }
- }
Add Comment
Please, Sign In to add comment