Advertisement
Aleksiev

CrossingSequences

Apr 15th, 2014
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.94 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Numerics;
  4.  
  5. class CrossingSequences
  6. {
  7.     static void Main()
  8.     {
  9.         int tribFirst = int.Parse(Console.ReadLine());
  10.         int tribSecond = int.Parse(Console.ReadLine());
  11.         int tribThird = int.Parse(Console.ReadLine());
  12.  
  13.         int spiralFirst = int.Parse(Console.ReadLine());
  14.         int spiralPlus = int.Parse(Console.ReadLine());
  15.  
  16.         int trib = 0;
  17.  
  18.         List<int> tribArr = new List<int>();
  19.         List<int> spiral = new List<int>();
  20.  
  21.         tribArr.Add(tribFirst);
  22.         tribArr.Add(tribSecond);
  23.         tribArr.Add(tribThird);
  24.  
  25.         while (trib < 1000000)
  26.         {
  27.             trib = tribFirst + tribSecond + tribThird;
  28.             tribFirst = tribSecond;
  29.             tribSecond = tribThird;
  30.             tribThird = trib;
  31.  
  32.             if (trib <= 1000000)
  33.             {
  34.                 tribArr.Add(trib);
  35.             }
  36.         }
  37.  
  38.         spiral.Add(spiralFirst);
  39.  
  40.         int spiralLast = spiralFirst;
  41.         int go = 0;
  42.         int goCount = 0;
  43.         int gosLeft = 0;
  44.  
  45.         while (spiralLast < 1000000)
  46.         {
  47.             spiralLast += spiralPlus;
  48.  
  49.             if (gosLeft > 0)
  50.             {
  51.                 gosLeft--;
  52.                 continue;
  53.             }
  54.  
  55.             goCount++;
  56.  
  57.             if (goCount == 2)
  58.             {
  59.                 go++;
  60.                 goCount = 0;
  61.             }
  62.  
  63.             if (spiralLast <= 1000000)
  64.             {
  65.                 spiral.Add(spiralLast);
  66.             }
  67.             gosLeft = go;
  68.         }
  69.  
  70.         int find = 0;
  71.  
  72.         foreach (int num in tribArr)
  73.         {
  74.             if (spiral.Contains(num))
  75.             {
  76.                 find = num;
  77.                 break;
  78.             }
  79.         }
  80.  
  81.         if (find > 0)
  82.         {
  83.             Console.WriteLine(find);
  84.         }
  85.         else
  86.         {
  87.             Console.WriteLine("No");
  88.         }
  89.     }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement