Advertisement
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 _01_Crossing_sequences
- {
- class Program
- {
- static void Main(string[] args)
- {
- var tribFirst = int.Parse(Console.ReadLine()); //[1...1000000]
- var tribSecond = int.Parse(Console.ReadLine()); //[1...1000000]
- var tribThird = int.Parse(Console.ReadLine()); //[1...1000000]
- var num = int.Parse(Console.ReadLine()); //[1...1000000]
- var spiralStep = int.Parse(Console.ReadLine()); //[1...1000000]
- int tribCurrent = tribFirst + tribSecond + tribThird;
- int spiralCurrent = num;
- int spiralStepMult = 1;
- int step = 1;
- while (tribCurrent <= 1000000 && spiralCurrent <= 1000000)
- {
- if (tribCurrent == spiralCurrent || spiralCurrent == tribFirst
- || spiralCurrent == tribSecond || spiralCurrent == tribThird)
- {
- Console.WriteLine(spiralCurrent);
- break;
- }
- else if (tribCurrent < spiralCurrent)
- {
- tribCurrent = tribFirst + tribSecond + tribThird;
- tribFirst = tribSecond;
- tribSecond = tribThird;
- tribThird = tribCurrent;
- }
- else
- {
- spiralCurrent += spiralStepMult * spiralStep;
- if (step % 2 == 0) spiralStepMult++;
- step++;
- }
- }
- if (tribCurrent > 1000000 || spiralCurrent > 1000000) Console.WriteLine("No");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement