A:
做法:
数据比较小,用求和公式(n+1)*n/2,减去所有2的幂即可
点击查看代码
// Problem: A. Tricky Sum
// Contest: Codeforces - Educational Codeforces Round 1
// URL: https://codeforces.com/contest/598/problem/A
// Memory Limit: 256 MB
// Time Limit: 1000 ms
// Author: a2954898606
// Create Time:2023-11-29 13:30:11
//
// Powered by CP Editor (https://cpeditor.org)
/*
/\_/\
(o o)
/ \
// ^ ^ \\
/// \\\
\ |
\_____/
/\_ _/\
*/
#include<bits/stdc++.h>
#define all(X) (X).begin(),(X).end()
#define all2(X) (X).begin()+1,(X).end()
#define pb push_back
#define mp make_pair
#define sz(X) (int)(X).size()
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
using namespace std;
typedef long long unt;
typedef vector<long long> vt_unt;
typedef vector<int> vt_int;
typedef vector<char> vt_char;
template<typename T1,typename T2> inline bool ckmin(T1 &a,T2 b){
if(a>b){
a=b;
return true;
}
return false;
}
template<typename T1,typename T2> inline bool ckmax(T1 &a,T2 b){
if(a<b){
a=b;
return true;
}
return false;
}
namespace smart_math{
long long quickpow(long long a,long long b,long long mod=0){
long long ret=1;
while(b){
if(b&1)ret*=a;
if(mod)ret%=mod;
b>>=1;
a*=a;
if(mod)a%=mod;
}
if(mod)ret%=mod;
return ret;
}
long long quickmul(long long a,long long b,long long mod=0){
long long ret=0;
while(b){
if(b&1)ret+=a;
if(mod)ret%=mod;
b>>=1;
a=a+a;
if(mod)a%=mod;
}
if(mod)ret%=mod;
return ret;
}
long long ceil_x(long long a,long long b){
if(a%b==0)return a/b;
else return (a/b)+1;
}
}
using namespace smart_math;
const long long mod=1e9+7;
const long long N=310000;
const long long M=300;
int solve(){
unt ans=0;
unt n;
cin>>n;
ans=(n)*(n+1)/2;
for(unt i=0;i<=63;i++){
unt sum=quickpow(2,i);
if(sum<=n){
ans-=2*sum;
}
if(sum>n)break;
}
cout<<ans<<endl;
return 0;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
t=1;
cin>>t;
while(t--){
int flag=solve();
if(flag==1) YES;
if(flag==-1) NO;
}
return 0;
}