30:00
Given two non-negative integers low and high, return how many odd numbers lie between low and high, both included.
0≤low≤high≤1090 \leq \text{low} \leq \text{high} \leq 10^90≤low≤high≤109
Run code to see results.
Count the odd numbers in [3, 7]. Instead of checking 5 numbers, count odds from 0 up to high, then remove the ones below low.
0..7 in pairs (even, odd)
■ odd, counted
prefix counts
odds in [0, 7] = (high + 1) // 2
odds in [0, 2] = low // 2
odds in [3, 7]
answer
Count the odd integers between low and high, both ends included. With high up to 10^9 a loop is too slow, but a prefix count over pairs of numbers gives the answer in two divisions.