(Edited answer to adressaddress the edited question, corrected original answer and calculation below)
Generally speaking, if you somehow managed to get a spaceship moving arbitrarily close to the speed of light, the the astronauts in it could reach any destination in a short amount of time – from their perspective. This is because their time $t'$ is related to the time of a "stationary" observer $t$ by
$$t'=\frac{t}{\gamma}=t\sqrt{1-\frac{v^2}{c^2}}$$
and
$$\lim_{v\to c}\gamma=\infty\implies\lim_{v\to c}t'=0$$
So the problem is getting a spacecraft to move this fast. As I calculated below, one would need about $5.13\cdot10^{26}\mathrm{J}$$1.1\cdot10^{29}\mathrm{J}$ to move a $10000\mathrm{t}$ spacecraft to a high enough velocity.
Let the velocity at which the spacecraft travels be $v$. Then $$t=\frac{2.537\cdot10^6\mathrm{ly}}{v}\approx\frac{2.4\cdot10^{22}\mathrm{m}}{v}$$ is the time that elapses until the spacecraft reaches M31 as measured by the stationary observers on earth1 and $$t'=\frac{t}{\gamma}=t\sqrt{1-\frac{v^2}{c^2}}$$ is the time measured by the astronauts.
The average age of an astronaut is 34 (Source). So we would want the astronauts on such a mission to only age around 20 years. So
$$t'=20\mathrm{y}=6.307\cdot10^8\mathrm{s}=t\sqrt{1-\frac{v^2}{c^2}}\\6.307\cdot10^8\mathrm{s}=\frac{2.4\cdot10^{22}\mathrm{m}}{v}\sqrt{1-\frac{v^2}{c^2}}\\\implies v=299792\frac{\mathrm{km}}{\mathrm{s}}\simeq c=299792.458\frac{\mathrm{km}}{\mathrm{s}}$$$$t'=20\mathrm{y}=6.307\cdot10^8\mathrm{s}=t\sqrt{1-\frac{v^2}{c^2}}\\6.307\cdot10^8\mathrm{s}=\frac{2.4\cdot10^{22}\mathrm{m}}{v}\sqrt{1-\frac{v^2}{c^2}}\\\implies v\approx299792457.99\frac{\mathrm{m}}{\mathrm{s}}\simeq c=299792458\frac{\mathrm{m}}{\mathrm{s}}$$
So the required velocity for the astronauts to reach M31 alive is extremely close to the speed of light. If we assume the mass of the spaceship to be $10000000\mathrm{kg}$ which is listed on the Wikipedia page on Project Orion for an "Advanced interplanetary" vehicle, the energy required to get to this velocity is
$$E=(\gamma-1)m_oc^2\approx5.13\cdot10^{26}\mathrm{J}$$$$E=(\gamma-1)m_oc^2\approx1.1\cdot10^{29}\mathrm{J}$$
Again, linklink to computation
For comparison, this is about 1.5 times as much ashalf of the totalrotational energy output of the sun every secondentire earth (Source).
Other problems could be the spacecraft not withstanding the extreme forces when accelerated to almost light speed or the spacecraft hitting debris at high velocities, which would probably damage it significantly.
1 Assuming no acceleration is needed – which of course would be necessary, but I will ignore it for the sake of simplicity.
Note: It is not impossible that I made mistakes during this calculation. If someone notices them, please comment so I can try to correct them.