Data Structures & AlgorithmsVery hardGATE CS · ICPC regional

A robot on a circle of 8 positions (0 to 7) starts at 0 and jumps 3 positions forward each step, wrapping around. After how many steps does it first return to position 0?

  1. A. 8
  2. B. 9
  3. C. 10
  4. D. 12

Correct answer: A. 8

Since gcd(3, 8) = 1, the jumps visit every position before returning, so the robot returns after 8 steps.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic