Problem. With eggs and a building of floors, find the highest floor from which an egg survives, minimizing the worst-case number of drops. A broken egg is lost; a surviving egg can be reused.

Invert the question: with eggs and drops, how many floors can be handled? Drop from floor : if it breaks, floors below remain with one egg less; otherwise floors above remain. So , whose solution is .

EggsAnswer
1 drops (linear scan from the bottom)
2smallest with : 14 for 100 floors
binary search,
generalbinary search on with
long long eggFloors(int eggs, long long drops) {   // max floors decidable: sum_{i=1..eggs} C(drops, i), capped
    long long s = 0, c = 1;
    for (int i = 1; i <= eggs && i <= drops; i++) {
        c = c * (drops - i + 1) / i;               // exact: C(d, i) = C(d, i-1) * (d-i+1) / i
        s += c; if (s >= (long long)4e18 || c >= (long long)4e18) return (long long)4e18;
    }
    return s;
}
long long minDrops(int eggs, long long floors) {   // smallest d with eggFloors(eggs, d) >= floors
    long long lo = 0, hi = floors;
    while (lo < hi) { long long m = (lo + hi) / 2; if (eggFloors(eggs, m) >= floors) hi = m; else lo = m + 1; }
    return lo;
}