水题,考虑到 l,r,特别小,可以直接暴力统计。当然也可以算两个前缀和,统计“前x个数中有多少个偶数”,然后直接左右端点作差即可。

#include<bits/stdc++.h>
using i64 = long long;

int main() {
    std::cin.tie(nullptr)->sync_with_stdio(false);

    int l, r;
    std::cin >> l >> r;
    std::cout << r / 2 - (l - 1) / 2;
    // int cnt = 0;
    // for (int i = l; i <= r; i++) {
    //     cnt += (i % 2 == 0);
    // }

    // std::cout << cnt;

    return 0;
}

https://www.nowcoder.com/discuss/727521113110073344