So the question asks to find a topology on $\mathbb{R}$ so that all the polynomials are continuous functions from $\mathbb{R}$ to $\mathbb{R}$ but $\cos(x)$ is not continuous as a function from $\mathbb{R}$ to $\mathbb{R}$.
I looked at another similar question in stack exchange: A Topology such that the continuous functions are exactly the polynomials I think this is a special case of my question since it requires all other functions to not be continuous.
Other than that I thought maybe the solution could be based on how cosine is a periodic function unlike the polynomials, so maybe I should take out some infinite sets from the topology but that still wouldn't be enough since the topology would be closed under unions. So I am not even sure if there exists such topology.