Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Numerics;
- class CrossingSequences
- {
- static void Main()
- {
- int tribFirst = int.Parse(Console.ReadLine());
- int tribSecond = int.Parse(Console.ReadLine());
- int tribThird = int.Parse(Console.ReadLine());
- int spiralFirst = int.Parse(Console.ReadLine());
- int spiralPlus = int.Parse(Console.ReadLine());
- int trib = 0;
- List<int> tribArr = new List<int>();
- List<int> spiral = new List<int>();
- tribArr.Add(tribFirst);
- tribArr.Add(tribSecond);
- tribArr.Add(tribThird);
- while (trib < 1000000)
- {
- trib = tribFirst + tribSecond + tribThird;
- tribFirst = tribSecond;
- tribSecond = tribThird;
- tribThird = trib;
- if (trib <= 1000000)
- {
- tribArr.Add(trib);
- }
- }
- spiral.Add(spiralFirst);
- int spiralLast = spiralFirst;
- int go = 0;
- int goCount = 0;
- int gosLeft = 0;
- while (spiralLast < 1000000)
- {
- spiralLast += spiralPlus;
- if (gosLeft > 0)
- {
- gosLeft--;
- continue;
- }
- goCount++;
- if (goCount == 2)
- {
- go++;
- goCount = 0;
- }
- if (spiralLast <= 1000000)
- {
- spiral.Add(spiralLast);
- }
- gosLeft = go;
- }
- int find = 0;
- foreach (int num in tribArr)
- {
- if (spiral.Contains(num))
- {
- find = num;
- break;
- }
- }
- if (find > 0)
- {
- Console.WriteLine(find);
- }
- else
- {
- Console.WriteLine("No");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement