Sequences, sets and element position in the set.

664 Views Asked by At

I have a sequence Q with the length of N.

This is the fragment of this sequence:

68 70 72 74 76 78 80

The sequence has been divided into the sets of 4 elements each.

I know the first element of the set. And i need find position of the given element in the set:

For example: let take the set: 60 62 64 66,

I know that the first element is 60, then i was given element 64 and i need to find its position in the set. This is simple: A(n) = A + (n - 1)*2 -> 64 = 60 + (n-1)*d thus n = 3

I have found the position of the given element in the current set.

Now the hardest part! The sequence Q is still divided onto sets of 4, BUT it gets reset every 40 items:

74 76 78 80 82 42 44 46 48 50 52 54 56

How would i find the position of the given element in the set of 4 in this case?

Any ideas?

P.S. this is a real life problem i need to solve to finish my programming task :)

EDIT

I also know the N (length of the sequence Q)

EDIT

Sequence can start with any even number