Skip to content

Instantly share code, notes, and snippets.

@voquanghoa voquanghoa/Solution.cs
Last active Apr 12, 2019

Embed
What would you like to do?
int sequenceElement(int[] a, int n)
{
int number = a[0] * 10000 + a[1] * 1000 + a[2] * 100 + a[3] * 10 + a[4];
int beginer = number;
if (n < 5)
{
return a[n];
}
var list = new List<int>();
do
{
list.Add(number);
number = (number % 10000) * 10
+ ((number / 10000) % 10
+ (number / 1000) % 10
+ (number / 100) % 10
+ (number / 10) % 10
+ (number / 1) % 10) % 10;
} while (beginer != number);
return list[(n - 4) % list.Count] % 10;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.