A Normal Sequence

Published by Werdna in

Consider a sequence where the first two numbers are 0 and 1 and the next number of the sequence is the sum of the previous two numbers modulo three.

Create a function that finds the $nth element of the sequence.

Examples

normalSequence(1) ➞ 0

normalSequence(2) ➞ 1

normalSequence(3) ➞ 1
// (0+1)%3 = 1

normalSequence(20) ➞ 2

Notes

  • 1 ≤ N ≤ 10^19
  • A hint in comments section.
Watch a quick demo on how Edabit works.