Hackerearth mystery problem

here is the link to the the problem.

here is the link to the solution of the problem

i am passing all the testcases with the above solution but why i am not passing all the testcases when i am using library function to count the no of bits. i am using library function __builtin_popcount().

@ankitkumarmbill1 It is not giving correct answer as constraints of n are too large that 10^18 ,so I suggest you to use bitwise operator to solve this problem.Hope you get it.

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.

#include<bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
unsigned long long int n,c;
while(!cin.eof())
{
cin>>n;
c=0;
while(n)
{
n=n&(n-1);
c++;
}
std::cout<<c<<endl;
}
return 0;
}
i use bitwise operator but it not pass last test case???

@abhinavraj167 hey use long long int in place of int ,it will get pass.

I use unsigned long long int but it will not pass see my above solution

@abhinavraj167 hey made some changes check this:

#include<iostream>
#define ll long long
using namespace std;

ll countbits(ll n){

  ll count =0;
  while(n){

    n = n&(n-1);
    count++;

  }

  return count;

}
int main()
{
    ll x;
    while(!cin.eof())
    {
        cin>>x;

        cout<<countbits(x)<<endl;
    }
    return 0;   
}

this solution is not accepted

@abhinavraj167 bro fir test case me dikkt hogi,kyunki editorial me bhi aisa hi dia hai.