int closestFibonacci(int n)
{
int current = 0;
int next = 1;
while (n >= next) {
long temp = (long)current + (long)next;
if (temp > 2147483647) { // 2,147,483,647 - this is maximal int value
return next;
}
current = next;
next = (int)temp;
}
return current;
}