Reputation: 1464
I want to solve this problem:
For a given sequence, a[0], a[1], a[2],..., a[n-1]
, please find "period" of the sequence.
The period is the minimum integer k (k >= 1) that satisfies a[i] = a[i+k] for all valid i, and also k is a divisor of n.
My current solution is calculating all divisor of n (this is k) and test for all k, but it takes O(n * d(n))
. I think it is slow.
Is there any efficient algorithm?
Upvotes: 3
Views: 3289