Use of in bulid fxn

I am using in build function __builtin__popcount(n);
in a loop but its giving zero for infinite time i guess why so!?

Hello @raj_pareek please share your code so that i can check.

#include<bits/stdc++.h>
using namespace std;
int main() {
int q;
cin>>q;
while(q–)
{
int a,b;
cin>>a>>b;
int ans=0;

    for(int i=a;i<=b;i++)
    {
        ans+=(__builtin_popcount(i));
    }

    cout<<ans<<endl;
}

return 0;
}

Hello @raj_pareek i have corrected and commented the code :


Happy Learninng!!

1 Like

why we have to do that??
int h=i;

@raj_pareek i was just checking that there is no need of it.
you can do that in you way also. but what i havecommented is the correction.

actually i was doing q-- already.
well thanks my issue is resolved.

if your issue is resolved please mark this doubt as resolved.
Happy Learning!!

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.