1
0
Fork 0

Add number/odds.cc

This commit is contained in:
subcrip 2024-04-10 13:58:58 +08:00
parent 0018dbf69f
commit ed523135db
1 changed files with 10 additions and 0 deletions

10
number/odds.cc Normal file
View File

@ -0,0 +1,10 @@
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);
};