数论+思维 D. Multipliers

codeforces #338 Div2 D. Multipliers

题意

给n个数
在这里插入图片描述
求 d 的所有约数相积得到的数的相积
所以答案应该是
在这里插入图片描述

ans mod 1e9+7

思路

所以关键是对于k的 考虑
考虑每个数pi出现的次数为num[i]
先考虑其单个ki应该是num[i]*(num[i]+1)/2(出现0,1,2,…num[i])
但是如果考虑其他的
在这里插入图片描述
因此快速幂即可

ps: ki可能会很大
那么可以用费马小定理
在这里插入图片描述
小细节
mod-1和2是非互质的 所以可以将在给 k取模时 2 (% mod2-2 就是说)
这样后面转换过来不会有丢失(就是 后来再 mod-1)
本质是通用求逆元(b=2)

在这里插入图片描述

AC代码

#include<bits/stdc++.h>
#define endl "\n"
#define INF 0x3f3f3f3f3f3f3f
typedef long long ll;
const ll mod = 1e9 + 7;
const double PI = acos(-1.0);
const double EI = exp(1.0);
const int N = 2e6 + 10;
const double eps = 1e-8;
using namespace std;
ll fast_pow(ll a, ll b)
{
	ll ans = a, res = 1;
	while (b>0)
	{
		if (b & 1)
			res = (res * ans) % mod;
		ans = (ans * ans) % mod;
		b /= 2;
	}
	return res;
}
ll inv(ll x) { return fast_pow(x, mod - 2); }
void solve()
{
	int n;
	cin >> n;
	map<ll, ll>M;
	for (int i = 1; i <= n; i++)
	{
		int x;
		cin >> x;
		M[x]++;
	}
	ll d = 1;
	for (auto t : M)
	{
		d = (d*(t.second + 1))%(2*mod-2);
	}
	ll ans = 1;
	for (auto t : M)
	{
		ans = (ans * fast_pow(t.first, t.second * d / 2 % (2 * mod - 2)) % mod);
	}
	cout << ans << endl;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(); cout.tie(0);
	//int t; cin >> t; while (t--)
	solve();
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值