I.数列乘积

给定一个长度为 n 的数列,首项为 a1 ,通项公式如下
在这里插入图片描述
请你求下面式子的结果:
在这里插入图片描述
其中
∏ 表示累乘,由于结果可能很大,我们输出最后结果对 10^9 + 7取模的结果。

输入格式

输出第一行两个整数 n,a1 ,分别表示数列长度和首项的值。

输出格式

输出表达式对 10^9 + 7 取模的结果。

#include <iostream>
using namespace std;
typedef long long int LL;
const int mod = 1e9 + 7;
LL pow_mod(LL x, LL y, int mod)
{
	LL res = 1, temp = x % mod;
	while (y)
	{
		if (y & 1)
		{
			res = res * temp % mod;
		}
		temp = temp * temp % mod;
		y >>= 1;
	}
	return res;
}
int main()
{
	LL n, a;
	cin >> n >> a;
	if (a == 1)
	{
		cout << pow_mod(2, n, mod) << endl;
	}
	else
	{
		LL p = pow_mod(2, n, mod - 1);
		LL res = pow_mod(a, p, mod) - 1;
		if (res < 0)
		{
			res += mod;
		} 
		res *= pow_mod(a - 1, mod - 2, mod);
		res %= mod;
		cout << res << endl;
	}
	return 0;
} 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值