Guest User

Untitled

a guest
Feb 10th, 2018
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.67 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace tribonacci
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int first = int.Parse(Console.ReadLine());
  14.             int second = int.Parse(Console.ReadLine());
  15.             int third = int.Parse(Console.ReadLine());
  16.             var forth = 0;
  17.             int newfirst = first;
  18.             int newsecond = second;
  19.             int newthird = third;
  20.             int matrixFirst = int.Parse(Console.ReadLine());
  21.             int matrixStep = int.Parse(Console.ReadLine());
  22.             int counter = -1;
  23.             int amplifier = matrixStep;
  24.  
  25.             while (true)
  26.             {
  27.                 for (int i = 0; i < 1; i++)
  28.                 {
  29.                     forth = newfirst + newsecond + newthird;
  30.                     newfirst = newsecond;
  31.                     newsecond = newthird;
  32.                     newthird = forth;
  33.                     if (forth >= 1000000)
  34.                     {
  35.                         break;
  36.                     }
  37.                     if (matrixFirst >= 1000000 && forth >= 1000000 && matrixFirst != forth)
  38.                     {
  39.                         Console.WriteLine("No");
  40.                         return;
  41.                     }
  42.                 }
  43.                 if (matrixFirst < forth)
  44.                 {
  45.                     counter++;
  46.                 }
  47.                 for (int i = counter; ; i++)
  48.                 {
  49.                     if (matrixFirst >= 1000000 && forth >= 1000000 && matrixFirst != forth)
  50.                     {
  51.                         Console.WriteLine("No");
  52.                         return;
  53.                     }
  54.                     if (matrixFirst == first || matrixFirst == second || matrixFirst == third)
  55.                     {
  56.                         Console.WriteLine(matrixFirst);
  57.                         return;
  58.                     }
  59.                     if (matrixFirst == forth)
  60.                     {
  61.                         Console.WriteLine(forth);
  62.                         return;
  63.                     }
  64.                     else if (matrixFirst < forth)
  65.                     {
  66.                         if (i > 1 && i % 2 == 0)
  67.                         {
  68.                             matrixStep += amplifier;
  69.                             counter++;
  70.                         }
  71.                         matrixFirst += matrixStep;
  72.                         continue;
  73.                     }
  74.                     else
  75.                     {
  76.                         break;
  77.                     }
  78.                 }
  79.             }
  80.         }
  81.     }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment