Skip to content

Instantly share code, notes, and snippets.

Created April 24, 2015 16:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/47642e5410997502c048 to your computer and use it in GitHub Desktop.
Save anonymous/47642e5410997502c048 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
class Program
{
static void Main()
{
long a = long.Parse(Console.ReadLine());
long b = long.Parse(Console.ReadLine());
long c = long.Parse(Console.ReadLine());
long spiralStart = int.Parse(Console.ReadLine());
long spiralStep = long.Parse(Console.ReadLine());
List<long> trib = new List<long>() { a, b, c };
List<long> spiral = new List<long>() { spiralStart };
bool check = false;
while (c <= 1000000)
{
long ctemp = c;
c = a + b + c;
a = b; b = ctemp;
trib.Add(c);
}
for (long poss = 1; spiralStart <= 1000000; poss++)
{
for (int m = 0; m < 2; m++)
{
long spiralStartTemp = spiralStart + poss * spiralStep;
spiral.Add(spiralStartTemp);
spiralStart = spiralStartTemp;
}
}
foreach (var item in trib)
{
if (spiral.Contains(item))
{
Console.WriteLine(item);
check = true;
return;
}
}
if (!check)
{
Console.WriteLine("No");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment