#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
#define PI(x) printf("%d",x)
#define SI(x) scanf("%d",&x)
#define P_(x) printf(" ")
const int INF=0x3f3f3f3f;
typedef long long LL;
int main(){
LL n;
int T;
SI(T);
while(T--){
LL temp=0,i=0;
scanf("%lld",&n);
while(pow(2,i)<=n){
temp+=pow(2,i);
i++;
}
printf("%lld\n",n*(n+1)/2-2*temp);
}
return 0;
}c++的使用,用来计算数列和,其中凡是2的次方数均为负数;
本文介绍了一段C++代码,用于计算一个特殊的数列和:从1到n的所有整数之和减去所有2的幂次方数的两倍。通过循环和条件判断实现算法,适用于计算机科学领域的初学者学习。
371

被折叠的 条评论
为什么被折叠?



