签到水题…然后我一直没做这题
加法的话乘法逆元搞一搞,亦或的话因为每次可以先确定二进制中前面几位,所以倒退一下就好了
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
unsigned int Pow(unsigned int x,unsigned int y){
unsigned int ret=1;
for(;y;y>>=1,x=x*x) if(y&1) ret=ret*x;
return ret;
}
int main(){
int q;
scanf("%d",&q);
while(q--){
unsigned int n,t; scanf("%u",&n);
t=n*Pow((1<<16)+1,(1U<<31)-1); n=t;
t=n&~((1U<<21)-1); t=n^(t>>11); t=n^(t>>11); n=t;
t=n*Pow((1<<3)+1,(1U<<31)-1); n=t;
t=n&~((1U<<26)-1); for(int i=1;i<=6;i++) t=n^(t>>6); n=t;
t=n*Pow((1<<10)+1,(1U<<31)-1);
printf("%u\n",t);
}
return 0;
}
本文介绍了一种使用位运算和乘法逆元解决特定数学问题的方法。通过位运算来确定二进制数的各位状态,利用乘法逆元进行数值计算。代码实现了具体的算法流程,包括幂运算、位操作等。
493

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



