Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Scanner;
- public class CrossingSequences {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- long t1 = scan.nextLong();
- long t2 = scan.nextLong();
- long t3 = scan.nextLong();
- long t4 = 0;
- long s1 = scan.nextLong();
- long s2 = scan.nextLong();
- List<Long> tribonacci = new ArrayList<>();
- List<Long> sequence = new ArrayList<>();
- tribonacci.add(t1);
- tribonacci.add(t2);
- tribonacci.add(t3);
- sequence.add(s1);
- int i =1;
- while(t4<1000000 || s1<1000000){
- t4 = t1+t2+t3;
- tribonacci.add(t4);
- t1=t2;
- t2=t3;
- t3=t4;
- for (int j = 1; j < 3; j++) {
- s1 += s2 * i;
- sequence.add(s1);
- }
- i++;
- }
- boolean found = false;
- for (int k = 0; k < tribonacci.size(); k++) {
- if (found) {
- break;
- }
- for (int j = 0; j < sequence.size(); j++) {
- if (tribonacci.get(k).equals(sequence.get(j))) {
- if(tribonacci.get(k) <= 1000000){
- found = true;
- System.out.println(tribonacci.get(k));
- break;
- }
- }
- }
- }
- if(found==false){
- System.out.println("No");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement