Codeforces 1362C. Johnny and Another Rating Drop Solution
_builtin_popcount(x): This function is used to count the number of one’s(set bits) in an integer.
- Example:
if x = 4 binary value of 4 is 100 Output: No of ones is 1
Solution in C++: ///**********ALLAH IS ALMIGHTY************/// ///AH Tonmoy ///Department of CSE,23rd batch ///Islamic University,Bangladesh
- #include<bits/stdc++.h>
- using namespace std;
- int main()
- {
- long long n,t;
- cin>>t;
- while(t--)
- {
- cin>>n;
- cout<<2*n-__builtin_popcountll(n)<<endl;
- }
- }
No comments