D(6)=18 means that 1, 2, 3, 6, 9, 18 are all divisors of M. That accounts for all of D(1)-D(6). So M=2^x*3^y*n^z for some integers x>=1, y>=2, and z>=0.
x must be 1, otherwise 4 would be a divisor which contradicts the requirement D(6)=18.
z=0 or 1, otherwise there would be at least 18 divisors which contradicts the requirement M has precisely 16 positive integer divisors.
If z=0 then y=7 and M=2*3^7. D(8) and D(9) then would be 54 and 81. 81-54=27 so this is not a number M.
Then z=1. y must be 3 for M to have 16 divisors, then M=2*3^3*n. The 8 known divisors are then 1, 2, 3, 6, 9, 18, 27, 54. This also implies n must be prime.
If n>54 then D(9)=n and D(8)=54. n-54=17 has a solution of n=71. 71 is prime so forms a solution M = 2*3^3*71 = 3834.
If 54>n>27 then D(9)=54 and D(8)=n. 54-n=17 has a solution of n=37. 37 is prime so forms a solution M = 2*3^3*37 = 1998.
If 27>n then D(9)=54 and D(8)=27. 54-27=27, not 17 so cannot form a solution.
In summary, M = 3834 or 1998.