Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace tribonacci
- {
- class Program
- {
- static void Main(string[] args)
- {
- int first = int.Parse(Console.ReadLine());
- int second = int.Parse(Console.ReadLine());
- int third = int.Parse(Console.ReadLine());
- var forth = 0;
- int newfirst = first;
- int newsecond = second;
- int newthird = third;
- int matrixFirst = int.Parse(Console.ReadLine());
- int matrixStep = int.Parse(Console.ReadLine());
- int counter = -1;
- int amplifier = matrixStep;
- while (true)
- {
- for (int i = 0; i < 1; i++)
- {
- forth = newfirst + newsecond + newthird;
- newfirst = newsecond;
- newsecond = newthird;
- newthird = forth;
- if (forth >= 1000000)
- {
- break;
- }
- if (matrixFirst >= 1000000 && forth >= 1000000 && matrixFirst != forth)
- {
- Console.WriteLine("No");
- return;
- }
- }
- if (matrixFirst < forth)
- {
- counter++;
- }
- for (int i = counter; ; i++)
- {
- if (matrixFirst >= 1000000 && forth >= 1000000 && matrixFirst != forth)
- {
- Console.WriteLine("No");
- return;
- }
- if (matrixFirst == first || matrixFirst == second || matrixFirst == third)
- {
- Console.WriteLine(matrixFirst);
- return;
- }
- if (matrixFirst == forth)
- {
- Console.WriteLine(forth);
- return;
- }
- else if (matrixFirst < forth)
- {
- if (i > 1 && i % 2 == 0)
- {
- matrixStep += amplifier;
- counter++;
- }
- matrixFirst += matrixStep;
- continue;
- }
- else
- {
- break;
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment