How to attach incremental numbers to the class with increase after nth element ?

How to attach incremental numbers to the class with increase after nth element ?

Hello
I am a beginner and have a question:

 i have the following div:
 
<div>
<span class="a"> some content</span>
<span class="a"> some content</span>
<span class="a"> some content</span>
<span class="a"> some content</span>
..
etc
</div>

 
I would like to attach dynamically incremental numbers
to the span class with increase after nth element .

 
 
 For example number increase every 3 items:
 
<span class="1a"> some content</span>
<span class="1a"> some content</span>
<span class="1a"> some content</span>
<span class="2a"> some content</span>
<span class="2a"> some content</span>
<span class="2a"> some content</span>
...

 I want to make some buttons to switch the increment value to every 10th, 20th, 50th, element etc.

Any suggestions ?

Thanks in Advance