HDU 5525 Product 数论
题意:
给出一个长度为\(n(1 \leq n \leq 10^5)\)的序列\(A_i\),\(N=\prod\limits_{i=1}^{n}i^{A_i}\)。求\(N\)的所有约数的乘积。
分析:
首先还是将\(N\)质因数分解,\(N=\prod\limits_{i=1}^{k}p_i^{e_i}\)。
考虑素因子\(p_a\)对结果的贡献,含有且仅含有\(p_a^x\)的约数有\(\frac{\prod\limits_{i=1}^{k}e_i+1}{e_a+1}\)个。
所以\(p_a\)对答案贡献了\(\frac{e_a(e_a+1)}{2} \cdot \frac{\prod\limits_{i=1}^{k}e_i+1}{e_a+1}\)次,也可以继续化简得到\(\frac{e_a\prod\limits_{i=1}^{k}e_i+1}{2}\)。
指数太大,根据费马小定理,我们可以对\(MOD-1\)取模。
指数第一部分有个分母\(2\),由于不能计算\(MOD-1\)的逆元,所以可以先对\(2(MOD-1)\)取模。
第二部分可以通过计算前缀后缀积来避免除法。
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
const LL MOD = 1000000007;
const int maxn = 100000 + 10;
LL pow_mod(LL a, LL n) {
LL ans = 1;
while(n) {
if(n & 1) ans = ans * a % MOD;
a = a * a % MOD;
n >>= 1;
}
return ans;
}
int pcnt, prime[maxn], pos[maxn];
bool vis[maxn];
void preprocess() {
for(int i = 2; i < maxn; i++) {
if(!vis[i]) prime[++pcnt] = i;
for(int j = 1; j <= pcnt && i * prime[j] < maxn; j++) {
vis[i * prime[j]] = true;
if(i % prime[j] == 0) break;
}
}
for(int i = 1; i <= pcnt; i++) pos[prime[i]] = i;
}
int n;
LL p[maxn];
LL pre[maxn], suf[maxn];
int main()
{
preprocess();
while(scanf("%d", &n) == 1) {
memset(p, 0, sizeof(p));
for(int i = 1; i <= n; i++) {
int a; scanf("%d", &a);
if(i == 1 || a == 0) continue;
int t = i;
for(int j = 1; j <= pcnt; j++) {
if((LL) prime[j] * prime[j] > t) break;
if(t % prime[j] == 0) {
int cnt = 0;
while(t % prime[j] == 0) {
t /= prime[j];
cnt++;
}
p[j] += (LL)cnt * a;
p[j] %= 2 * (MOD - 1);
}
}
if(t > 1) { p[pos[t]] += a; p[pos[t]] %= 2 * (MOD - 1); }
}
int tot = pcnt;
while(tot > 1 && p[tot] == 0) tot--;
pre[0] = suf[tot+1] = 1;
for(int i = 1; i <= tot; i++) pre[i] = pre[i-1] * (p[i] + 1) % (MOD - 1);
for(int i = tot; i >= 1; i--) suf[i] = suf[i+1] * (p[i] + 1) % (MOD - 1);
LL ans = 1LL;
for(int i = 1; i <= tot; i++) {
LL ta, tb;
if(p[i] % 2 == 0) ta = p[i]/2%(MOD-1)*((p[i]+1)%(MOD-1))%(MOD-1);
else ta = (p[i]+1)/2%(MOD-1)*(p[i]%(MOD-1))%(MOD-1);
tb = pre[i-1] * suf[i+1] % (MOD - 1);
ta = ta * tb % (MOD - 1);
ans = ans * pow_mod(prime[i], ta) % MOD;
}
printf("%lld\n", ans);
}
return 0;
}
HDU 5525 Product 数论的更多相关文章
- hdu 5525 Product 数论算贡献
Product Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Proble ...
- HDU 5525:Product 欧拉定理
Product Accepts: 21 Submissions: 171 Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072 ...
- hdu GuGuFishtion 6390 数论 欧拉函数
题目:http://acm.hdu.edu.cn/showproblem.php?pid=6390 直接开始证明: 我们设…………………………………….....…...............………… ...
- HDU 1299 基础数论 分解
给一个数n问有多少种x,y的组合使$\frac{1}{x}+\frac{1}{y}=\frac{1}{n},x<=y$满足,设y = k + n,代入得到$x = \frac{n^2}{k} + ...
- HDU 5317 RGCDQ (数论素筛)
RGCDQ Time Limit: 3000MS Memory Limit: 65536KB 64bit IO Format: %I64d & %I64u Submit Status ...
- HDU 1495 非常可乐(数论,BFS)
非常可乐 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submi ...
- HDU 1722 Cake (数论 gcd)(Java版)
Big Number 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1722 ——每天在线,欢迎留言谈论. 题目大意: 给你两个数 n1,n2 . 然后 ...
- L - LCM Walk HDU - 5584 (数论)
题目链接: L - LCM Walk HDU - 5584 题目大意:首先是T组测试样例,然后给你x和y,这个指的是终点.然后问你有多少个起点能走到这个x和y.每一次走的规则是(m1,m2)到(m1+ ...
- HDU 5666 Segment 数论+大数
题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5666 bc(中文):http://bestcoder.hdu.edu.cn/contests ...
随机推荐
- WebStorm技巧-集成命令行工具插件
打开菜单项 File -> Settings- 搜索插件 CMD Support,并安装. 重启WebStorm,在你的项目中新建一个Cmd script 文件,命名为build.cmd ...
- feign实现服务间的负载均衡
feign Feign是一个声明式的Web Service客户端,它使得编写Web Serivce客户端变得更加简单.我们只需要使用Feign来创建一个接口并用注解来配置它既可完成.它具备可插拔的注解 ...
- 关于React的require添加动态变化的路径
关于React的require添加动态变化的路径 直接这样写显然是不会有错误的 let path = require('../images/girl.png'); 但是如果你尝试着 var gg = ...
- CF1166C A Tale of Two Lands
思路: 搞了半天发现和绝对值无关. http://codeforces.com/blog/entry/67081 实现: #include <bits/stdc++.h> using na ...
- It is not the destination so much as the journey, they say.
It is not the destination so much as the journey, they say. 人家说目的地不重要,重要的是旅行的过程.<加勒比海盗>
- ios 设置cell的间距
1.设置假的间距,我们在tableviewcell的contentView上添加一个view,比如让其距离上下左右的距离都是10:这个方法是最容易想到的: 2.用UIContentView来代替tab ...
- Python3+Selenium3+webdriver学习笔记8(单选、复选框、弹窗处理)
#!/usr/bin/env python# -*- coding:utf-8 -*-'''Selenium3+webdriver学习笔记8(单选.复选框.弹窗处理)''' from selenium ...
- 通过Jenkins调用自动部署war包及jar包到服务器上的Shell脚本
1)部署war包#!/bin/bashif [ id>0];then echo"stopproject" kill −9 idelse echo "project ...
- 总结jboss控制台,得出一下结论(数据库连接池相关)
jboss控制台中: http://127.0.0.1:8080/jmx-console/HtmlAdaptor?action=inspectMBean&name=jboss.jca%3Ase ...
- selenium-Python之上传文件
对于web 页面的上传功能实现一般有一下两种方式 普通上传:普通的附件上传是将本地文件的路径作为一个值放在input标签中,通过form表单将这个值提交给服务器 插件上传:一般是指基于flash.ja ...