cf#516B. Equations of Mathematical Magic(二进制,位运算)
生活随笔
收集整理的這篇文章主要介紹了
cf#516B. Equations of Mathematical Magic(二进制,位运算)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
https://blog.csdn.net/zfq17796515982/article/details/83051495
題意:解方程:a-(a^x)-x=0 給出a的值,要求計算解(非負)的個數(shù)
題解:需要^和 - 起到相同的效果。
1^1=0 1-1=0
1^0=1 1-0=1
0^0=0 0-0=0,
0^1=1 0-1=-1
a的二進制位上為1時,x的二進制位上為1或者0,異或和減的效果相同。
a的二進制有幾個1,就表示解的個數(shù)有2的幾次方個
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
while(~scanf("%d",&t))
{
while(t--)
{
long long n;
scanf("%lld",&n);
long long ans=;
int num=;
while(n)
{
if(n&)
{
n/=;
num++;
}
else
{
n/=;
}
}
ans=pow(,num);
printf("%lld\n",ans);
}
}
return ;
}
總結(jié)
以上是生活随笔為你收集整理的cf#516B. Equations of Mathematical Magic(二进制,位运算)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: kindEditor 使用
- 下一篇: 如何快速搭建 Maven私服Nexus【