```
public class Solution : VersionControl {
public int FirstBadVersion(int n) {
decimal first = 1;
decimal last = n;
int mid = 1;
int lastbad = 1;
while (first <= last)
{
mid = Convert.ToInt32(Math.Round((first+last)/2));
if (IsBadVersion(mid))
{
last = mid-1;
lastbad = mid;
}
else
{
first = mid+1;
}
}
return lastbad;
}
}
```