Guest User

Untitled

a guest
Apr 3rd, 2018
1,130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.29 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. long long dp[50];
  4. int main()
  5. {
  6.     long long n;
  7.     scanf("%I64d",&n);
  8.     for (int i=1;i<50;i++)
  9.     dp[i]=2LL*dp[i-1]+(1LL<<(i-1));
  10.     n--;
  11.     long long ans=0;
  12.     for (int i=0;i<50;i++)
  13.     {
  14.         if (n&(1LL<<i))
  15.         ans+=dp[i]+(1LL<<i);
  16.     }
  17.     printf("%I64d",ans);
  18. }
Add Comment
Please, Sign In to add comment