Here's the formula. At the moment it requires a conditional statement, but you can always express it via a function returning 0 or 1 if you want pure functional form.
I wrote it as Perl function, to ease testing (I tested for all N<=20 and D between 0 and N)
sub div { my ($x, $y) = @_; return ($x-$x%$y)/$y }; # whole division
my $small_subsequence_length = div($N, $D);
my $big_subsequence_length = $small_subsequence_length + 1;
my $num_big_subseqiences = $N % $D;
my $num_total_big_subsequence_numbers = $big_subsequence_length * $num_big_subseqiences;
my $num_total_small_subsequence_numbers = $N - $num_total_small_subsequence_numbers;
my $num_small_subseqiences = div($num_total_small_subsequence_numbers, $small_subsequence_length);
sub sequence {
my $k = $_[0];
my ($subsequence_num, subsequence_offset);
if ($k > $num_total_big_subsequence_numbers) {
my $k2 = $k - $num_total_big_subsequence_numbers;
$subsequence_num = div($k2, $small_subsequence_length) + $num_big_subseqiences;
$subsequence_offset = ($k2 % $small_subsequence_length) * $D;
} else {
$subsequence_num = div($k, $big_subsequence_length);
$subsequence_offset = ($k % $big_subsequence_length) * $D;
}
return $subsequence_offset + $subsequence_num;
}