题解 | 小q的数列

小q的数列

https://www.nowcoder.com/practice/8ea1e0d996f64e15961ae42e658a04a7

#include<bits/stdc++.h>
using namespace std;
#define int long long
int T;
int n;

void solve(){
	
	if(n==0){
		cout<<0<<" "<<0<<endl;
		return;
	}
	
	int count=0;
	
	while(n>0){
		n=n&(n-1);
		count++;
	}
	
	int res=(((int)1<<count)-1);  //1 本属于int类型,将其转换为long long
	
	cout<<count<<" "<<res<<endl;
	
}

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin>>T;
	
	while(T--){
		cin>>n;
		solve();
	}

    return 0;
}


全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务