HDU 5525 Product

Problem Description
Given a number sequence  A1,A2....An ,indicating  N=ni=1iAi .What is the product of all the divisors of N?
 

Input
There are multiple test cases.
First line of each case contains a single integer n. (1n105)
Next line contains n integers  A1,A2....An ,it's guaranteed not all  Ai=0 . (0Ai105) .
It's guaranteed that  n500000 .
 

Output
For each test case, please print the answer module  109+7  in a line.
 

Sample Input
  
  
4 0 1 1 0 5 1 2 3 4 5
 

Sample Output
  
  
36 473272463
要注意过程当中的溢出问题
#include<cstdio>
#include<cmath>
#include<queue>
#include<stack>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long LL;
const LL base = 1e9 + 7;
const LL mod = 1e9 + 6;
const int maxn = 100005;
int n, a[maxn], f[maxn], p[maxn], tot = 0, x;
LL ans[maxn], qur, L[maxn], R[maxn];

struct point
{
	int x, y;
	point(int x = 0, int y = 0) :x(x), y(y){}
};
vector<point> map[maxn];

void pre()
{
	for (int i = 2; i < maxn; i++)
	{
		if (!f[i]) { map[i].push_back(point(tot, 1)); f[i] = tot; p[tot++] = i; }
		else
		{
			for (int j = 0; j < tot; j++)
			if (i%p[j] == 0)
			{
				int u = i / p[j], v = 1;
				for (int k = 0; k < map[u].size(); k++)
					if (map[u][k].x != j) map[i].push_back(map[u][k]);
					else v += map[u][k].y;
				map[i].push_back(point(j, v));
				break;
			}
		}
		for (int j = 0; j < tot&&i*p[j] < maxn; j++)
		{
			f[i*p[j]] = -1;
			if (i%p[j] == 0) break;
		}
	}
}

LL get(LL x, LL y)
{
	LL ans = 1;
	for (x %= base; y; y >>= 1)
	{
		if (y & 1) ans = ans*x%base;
		x = x*x%base;
	}
	return ans;
}

int main()
{
	pre();
	while (scanf("%d", &n) != EOF)
	{
		for (int i = 0; i <= tot; i++) ans[i] = 0;
		for (int i = 1; i <= n; i++)
		{
			scanf("%d", &x);
			for (int j = 0; j < map[i].size(); j++)
			{
				ans[map[i][j].x] += (LL)map[i][j].y*x;
			}
		}
		for (int i = 0; i < tot; i++)
		{
			L[i] = (ans[i] + 1) % mod;
			if (i) L[i] = L[i] * L[i - 1] % mod;
		}
		for (int i = tot; i; i--)
		{
			R[i] = (ans[i] + 1) % mod;
			if (i < tot) R[i] = R[i] * R[i + 1] % mod;
		}
		qur = 1;
		for (int i = 0; i < tot; i++)
		{
			LL u = ans[i], v = ans[i] + 1;
			if (u % 2 == 0) u = u / 2; else v = v / 2;
			u = (u%mod)*(v%mod) % mod;
			if (i) u = u*L[i - 1] % mod;
			u = u*R[i + 1] % mod;
			qur = qur*get(p[i], u) % base;
		}
		printf("%I64d\n", qur);
	}
	return 0;
}


 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值