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 925 (Div. 3) 1931D. Divisible Pairs Solution

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

Powered by Blogger.