K - Happy Equation

Little Sub has just received an equation, which is shown below, as his birthday gift.
在这里插入图片描述
Given the value of , please help Little Sub count the number of x(1<=x<=2^p)
which satisfies the equation.

Input

There are multiple test cases. The first line of the input contains an integer T (about 1000), indicating the number of test cases. For each test case:
The first and only line contains two integers a and p (1<=a<=10^9, 1<=p<=30).

Output

For each test case output one line containing one integer, indicating the answer.

Sample Input

2
6 12
8 16

Sample Output

1023
16383
题意:给你一个式子,让你求出在【1,2^p】中满足式子中的个数。(这是17年广西邀请赛原题,gg )(hdu6189)

思路:有点麻烦写到纸上了,上图。
在这里插入图片描述

这是当a为奇数时打表的函数和数据 :

在这里插入图片描述

在这里插入图片描述
AC代码:

#include<iostream>
#include<cmath>
using namespace std;
typedef long long ll;
ll quickmul(ll a,ll b,ll mod)
{
	ll temp=a,ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*temp)%mod;
		temp=(temp*temp)%mod;
		b>>=1;
	}
	return ans;
}
void init()
{
	ll ans=0;
	ll mod=1<<20;
	for(int a=1;a<=50;a++)
	{
		for(int i=1;i<=20;i++)
		{
			if(quickmul(a,i,mod)%mod==quickmul(i,a,mod)%mod)
			{
				ans++;
			}
		}
		if(a&1)	cout<<"奇数"<<endl; 
		cout<<ans<<endl;
		
		ans=0;
	}
			
}
int main()
{
//	init();
	ll t;
	cin>>t;
	while(t--)
	{
		ll a,p;
		cin>>a>>p;
		if(a&1)
		{
			cout<<"1"<<endl;
			continue;
		}
		else
		{
			ll ans=0;
			ll mod=1<<p;
			for(int i=1;i<=p;i++)
			{
				if(quickmul(a,i,mod)%mod==quickmul(i,a,mod)%mod)
				{
					ans++;
				}
			}
			ll q1;
				q1=p/a;
			if(p%a)
				q1++;
			ll l=1<<q1;
			ans+=(mod/l-p/l);
			cout<<ans<<endl;
		}
		
	}
	return 0;
}
  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

aaHua_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值