a: \(M=\dfrac{a^2+a+1}{a^2+1}:\left(\dfrac{a}{a-1}-\dfrac{2a}{\left(a-1\right)\left(a^2+1\right)}\right)\)
\(=\dfrac{a^2+a+1}{a^2+1}:\dfrac{a^3+a^2-2a}{\left(a-1\right)\left(a^2+1\right)}\)
\(=\dfrac{a^2+a+1}{a^2+1}\cdot\dfrac{\left(a-1\right)\left(a^2+1\right)}{a\left(a+2\right)\left(a-1\right)}\)
\(=\dfrac{a^2+a+1}{a^2+2a}\)
Để M là số nguyên thì \(a^2+a+1⋮a^2+2a\)
\(\Leftrightarrow a^2+2a-a+1⋮a^2+2a\)
=>-a^2+a chia hết cho a^2+2a
=>-a^2-2a+3a chia hết cho a^2+2a
=>3a chia hết cho a^2+2a
=>3 chia hết cho a+2
=>\(a+2\in\left\{1;-1;3;-3\right\}\)
hay \(a\in\left\{-1;-3;-5\right\}\)
b: Để M=7 thì \(a^2+a+1=7a^2+14a\)
=>7a^2+14a-a^2-a-1=0
=>6a^2+13a-1=0
hay \(a=\dfrac{-13\pm\sqrt{193}}{12}\)