Skip to content

区间内求奇数个数 ​

c++
int countOdds(int low, int high){
    if(low%2==1){
        return 1+(high-low)/2;
    }
    else{
        if(high-low>=1)
        return  1+(high-low-1)/2;
        else{
            return 0;
        }
    }


}

[l,r]之间的奇数

(r+1)/2-l/2