a: \(P=\left(\dfrac{\left(x+1\right)^2}{\left(x-1\right)\left(x+1\right)}-\dfrac{\left(x-1\right)^2}{\left(x-1\right)\left(x+1\right)}+\dfrac{x^2-4x-1}{\left(x-1\right)\left(x+1\right)}\right)\cdot\dfrac{x+2017}{x}\)
\(=\dfrac{x^2+2x+1-x^2+2x-1+x^2-4x-1}{\left(x-1\right)\left(x+1\right)}\cdot\dfrac{x+2017}{x}\)
\(=\dfrac{x^2-1}{\left(x-1\right)\left(x+1\right)}\cdot\dfrac{x+2017}{x}=\dfrac{x+2017}{x}\)
b: Để P là số nguyên thì \(x+2017⋮x\)
\(\Leftrightarrow x\in\left\{2017;-2017\right\}\)