1
0
Fork 0
cp-templates/number/odds.cc

11 lines
305 B
C++
Raw Normal View History

2024-04-10 13:58:58 +08:00
auto odds = [] (ll a, ll b) -> ll {
if (a % 2 == 0) a += 1;
if (b % 2 == 0) b -= 1;
if (a > b) return 0;
ll odd_sum = ((b + 1) / 2) * ((b + 1) / 2) - ((a - 1) / 2) * ((a - 1) / 2);
return odd_sum;
};
auto oddcount = [] (ll a, ll b) -> ll {
return (b - a) / 2 + (a & 1 | b & 1);
};