Advertisement
_Alpha_

Two set bits

Dec 15th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include <cmath>
  2. #include <cstdio>
  3. #include <vector>
  4. #include <iostream>
  5. #include <algorithm>
  6. using namespace std;
  7.  
  8.  
  9. int main() {
  10.     int t;
  11.     cin>>t;
  12.     double m=1e9+7;
  13.     while(t--){
  14.         long long int n,x=0,k=1,i,ans;
  15.         cin>>n;
  16.         n=n%(long)m;
  17.         k=(sqrt(1+8*n))/2;
  18.         x=(k*(k-1))/2;
  19.         i=(n-x-1)%(long)m;
  20.         //cout<<k<<" "<<x<<" ";
  21.         k=k%(long)m;
  22.         i=i%(long)m;
  23.         ans=(((long)1<<k)%(long)m+((long)1<<i)%(long)m)%(long)m;
  24.         cout<<ans<<endl;
  25.     }
  26.     return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement