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.
  1. Example:
    if x = 4
    binary value of 4 is 100
    Output: No of ones is 1
  2. Solution in C++:
    ///**********ALLAH IS ALMIGHTY************///
    ///AH Tonmoy
    ///Department of CSE,23rd batch
    ///Islamic University,Bangladesh
  3. #include<bits/stdc++.h>
  4. using namespace std;
  5. int main()
  6. {
  7. long long n,t;
  8. cin>>t;
  9. while(t--)
  10. {
  11. cin>>n;
  12. cout<<2*n-__builtin_popcountll(n)<<endl;
  13. }
  14. }

No comments

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h ...

Powered by Blogger.