**Part I**

Dividing loses precision. It may be very much precise, having an error in the order of ~ 10 ^ -12, but it won’t produce an exact result.

Instead you can do this.

omit this statement “tp = 360/k/1.;”

you know that tp * k == 360

therefore, h * k = 360 * (b - a)

```
h = (360 * (b-a)) / k;
if(h==180) ans=0;
```

Always use the precision loss statement in the final step. This way, you deal with exact figures.

**Part II**

We are not sure whether b is greater than a, therefore add the following statements:

tpa = a;

tpb = b;

a = min(tpa, tpb);

b = max(tpa, tpb);

You can find the solution link here.