To solve this problem it is necessary to take into account the concepts of Gravitational Force and Kinetic Energy.
The kinetic energy is given by the equation:

La energía gravitacional por,

Where m is the mass, v is the velocity, G the gravitational constant
the mass of the earth, m the mass of the sun and d the distance ..
The sum of the energies, we must be a total energy

By the type of orbit we know that
E> 0 is a hyperbolic orbit
E = 0 is a parabolic orbit
E <0 is a closed orbit.
In the case of hyperbolic orbit
E>0

The case of the comet is a closed orbit, so,
E<0

For parabolic orbit
E=0

For the sun and the earth


where 
For elliptical orbit