天天看点

牛客暑假多校训练营第一场-1001 Mod, Or and Everything

​​传送门​​

牛客暑假多校训练营第一场-1001 Mod, Or and Everything

题意:

思路:

#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll a[100];

int main()
{
  int t;
  cin>>t;
  for(int i = 1; i <= 60; i++)
  {
    a[i] = pow(2,i-1);
  }
  while(t--)
  {
    ll n;
    cin>>n;
    int cnt = 0;
    ll now = 1;
    for(int i = 1; i <= 64; i++)
    {
      now *= 2;
      if(now >= n)
      {
        cnt = i-1;
        break;
      }
    }
    ll ans = 0;
    for(int i = 1; i <= cnt; i++)
    {
      ans += a[i];
    }
    cout<<ans<<endl;
  }
}      

继续阅读