解题报告:HDU_6189 Law of Commutation (找规律)

题目链接


题意:

给定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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值