\(S=\left(2n+1\right)\left(n^2-3n-1\right)-2n^3+1\)
\(=2n\left(n^2-3n-1\right)+\left(n^2-3n-1\right)-2n^3+1\)
\(=2n^3-6n^2-2n+n^2-3n-1-2n^3+1\)
\(=\left(2n^3-2n^3\right)-\left(6n^2-n^2\right)-\left(2n+3n\right)-1+1\)
\(=-5n^2-5n=-5n\left(n+1\right)⋮5\)
\(S=\left(2n+1\right)\left(n^2-3n-1\right)-2n^3+1\)
\(=2n^3-6n^2-2n+n^2-3n-1-2n^3+1\)
\(=-5n^2-5n=-5n\left(n+1\right)⋮5\)
Vậy \(\left(2n+1\right)\left(n^2-3n-1\right)-2n^3+1⋮5\)