Ask Your Question

Revision history [back]

You can do it like this:

sage: R.<x> = PolynomialRing(ZZ)
sage: n = 3
sage: f = x^3 + 1
sage: all(n.divides(c) for c in f.coefficients())
False
sage: g = 3*f
sage: all(n.divides(c) for c in g.coefficients())
True

The same approach also works for multivariate polynomials:

sage: R.<x,y> = PolynomialRing(ZZ)
sage: n = 3
sage: f = x^3 + y^3
sage: all(n.divides(c) for c in f.coefficients())
False
sage: g = 3*f
sage: all(n.divides(c) for c in g.coefficients())
True

Instead of n.divides(c) (assuming n is a SageMath Integer, as it is above) you could also use c % n == 0.