File splitter by nth row

I need to split a file into n separate files of about the same size. The way the file will be split is at every nth row, starting with the first row, that row will be cut and copied to it's corresponding new file so that each file has unique records. Any 'leftovers' will go into the last file. e.g.

>ls 
sample.txt
> cat sample.txt
aab
aac
aad
aae
aaf
aag
aah
aai
aaj
aak
aal
aam

'Run command' with n=4
Desired output:

>ls -l
sample.txt
sample1.txt
sample2.txt
sample3.txt
sample4.txt
>cat sample1.txt
aab
aae
aai
aam
>cat sample2.txt
aac
aag
aal
>cat sample3.txt
aad
aaj
>cat sample4.txt 
aaf
aah
aak

# sample4.txt picked up the "leftovers".

Thanks in advance.

split -l 4 sample.txt <prefix>

The problem with the split command is that it takes sequential rows from the target file. It does not pull every nth line from the file as requested. This won't work.

Your required output is not consistent.
Try this solution:

awk '{print > ("sample"++c".txt");c=(NR%n)?c:0}' n=4 file

Use gawk, nawk or /usr/xpg4/bin/awk on Solaris.

Thanks Danmero. This works perfectly. If you could unpack this part of the Awk statement for my learning benfit, that would be extremely helpful and appreciated.

c=(NR%n)?c:0}