题意:
给定n,a,求区间 [ 1 , 1<<n ] 的数b 满足 的个数
思路:
打表发现以下规律
1、若a为奇数,答案为1
2、若a为偶数,则对于大于n的b,满足,其中a2,b2为a,b含2的因子个数
3、对于小于n的b,满足的情况有点多,直接暴力check
代码:
#include<bits/stdc++.h>
using namespace std;
inline long long qpow(long long x,long long y,long long mod){
long long res = 1;
while(y){
if(y&1)res = res * x % mod;
y>>=1;x = x * x % mod;
}return res;
}
int main()
{
int n,a,m;
while(scanf("%d%d",&n,&a)==2){ m = 1<<n;
if(a&1)printf("%d\n",1);
else {
int a2 = log2((a&-a)+0.5) , b2 = 1<<max(1,(n+a-1)/a) ;
int b = (n+a2-1)/a2 - 1;
int ans = max(0,m/b2-b/b2);
for(int i=2;i<=b;i+=2)if(qpow(a,i,m)==qpow(i,a,m))++ans;
printf("%d\n",ans);
}
}return 0;
}