题目链接:

  codeforces 615 D. Multipliers

题目描述:

  给出n个素数,这n个素数的乘积等于s,问p的所有因子相乘等于多少?

解题思路:

  需要求出每一个素数的贡献值,设定在这n个素数中,有m个不同的素数,可表示为s = p1^a1*p1^a2*p3^a3*p4^a4.....pn^an,根据唯一分解定理可知,s的因子有(a1+1)*(a2+1)+......+(an+1) 个,对于pi的权值可以理解为:pi这个因子不出现,s的因子个数为x = (a1+1)*(a2+1)*...*(ai-1+1)*(ai+1+1)*...*(an+1),而因子pi出现的策略有y = (ai+1)*ai/2种,所以pi的贡献值为:pix * y,对于 x 值可以利用前缀来维护,还有就是因为x * y可能会很大,对指数进行取余,要用小费马定理:(a^b)%mod = a^(b%(mod-1))%mod。

 #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define LL __int64 const LL mod = 1e9+;
const int maxn = ; map <LL, LL> mp;
LL ans, l[maxn], r[maxn], res[maxn]; LL Pow (LL x, LL n)
{
LL sum = ;
while (n)
{
if (n % )
sum =(sum * x) % mod;
x =(x * x) % mod; n /= ;
}
return sum;
} /**
题意:给出n个素数,求素数的乘积的约数的乘积在MOD上一个数
逆元
a^n%m= a^(n mod(m-1))%m;
*/
int main ()
{
LL m;
scanf ("%I64d", &m);
{
LL n = , x;
ans = ; for (int i=; i<m; i++)
{
scanf ("%I64d", &x); if (mp[x] == )
res[++ n] = x; mp[x] ++;
} sort (res, res+n);
l[] = r[n+] = ;
for (int i=; i<=n; i++)
{
l[i] = (l[i-] * (mp[res[i]] + )) % (mod - );
r[n-i+] = (r[n-i+] * (mp[res[n-i+]] + )) % (mod -);
} for (int i=; i<=n; i++)
{
LL tmp = (mp[res[i]] + ) * mp[res[i]] / % (mod -) * l[i-] % (mod -) * r[i+] % (mod - );
ans = (ans * Pow(res[i], tmp))%mod;
} printf ("%I64d\n", ans);
}
return ;
}
/**
6
101 103 107 109 101 103 */

codeforces 615 D. Multipliers (数论 + 小费马定理 + 素数)的更多相关文章

  1. codeforces 615 B. Longtail Hedgehog (DFS + 剪枝)

    题目链接: codeforces 615 B. Longtail Hedgehog (DFS + 剪枝) 题目描述: 给定n个点m条无向边的图,设一条节点递增的链末尾节点为u,链上点的个数为P,则该链 ...

  2. ACM-ICPC 2018 焦作赛区网络预赛G Give Candies(隔板定理 + 小费马定理 + 大数取模,组合数求和)题解

    题意:给你n个东西,叫你把n分成任意段,这样的分法有几种(例如3:1 1 1,1 2,2 1,3 :所以3共有4种),n最多有1e5位,答案取模p = 1e9+7 思路:就是往n个东西中间插任意个板子 ...

  3. [CodeForces - 1225C]p-binary 【数论】【二进制】

    [CodeForces - 1225C]p-binary [数论][二进制] 标签: 题解 codeforces题解 数论 题目描述 Time limit 2000 ms Memory limit 5 ...

  4. Codeforces Round #338 (Div. 2) D. Multipliers 数论

    D. Multipliers 题目连接: http://codeforces.com/contest/615/problem/D Description Ayrat has number n, rep ...

  5. Codeforces 615D Multipliers (数论)

    题目链接 Multipliers 题意很明确. 很显然答案可以表示成X ^ EXP % MOD 首先我们令N为输入的n个数的乘积.并且设N = (P1 ^ C1) * (P2 ^ C2) * ... ...

  6. Codeforces 919E Congruence Equation ( 数论 && 费马小定理 )

    题意 : 给出数 x (1 ≤ x ≤ 10^12 ),要求求出所有满足 1 ≤ n ≤ x 的 n 有多少个是满足 n*a^n  = b ( mod p ) 分析 : 首先 x 的范围太大了,所以使 ...

  7. Codeforces 622F 「数学数论」「数学规律」

    题意: 给定n和k,求 1 ≤ n ≤ 109, 0 ≤ k ≤ 106 思路: 题目中给的提示是对于给定的k我们可以求出一个最高次为k+1的关于n的通项公式. 根据拉格郎日插值法,我们可以通过k+2 ...

  8. 【14.67%】【codeforces 615D】Multipliers

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  9. Codeforces 515C 题解(贪心+数论)(思维题)

    题面 传送门:http://codeforces.com/problemset/problem/515/C Drazil is playing a math game with Varda. Let’ ...

随机推荐

  1. My app status is Ready for Sale but I cannot see my app on the App Store. Why? 为什么审核通过后 appstore中搜不到我的app

    这是苹果的官方解答 The following factors could prevent your app from showing up on the App Store: Make sure t ...

  2. 手游服务器php架构比较

    从swoole项目开始到现在,一直有人在问这个问题.今天来抽空讲一下它.为什么swoole非要使用纯C来写而不是PHP代码来实现,核心的原因有2点: 1. PHP无法直接调用操作系统API 如send ...

  3. 设置Android Studio工程布局文件的默认布局

    每次创建新的工程后,布局文件的的布局总是ConstraintLayout,如何更改? 进入Android Studio安装目录,用文本编辑器打开文件plugins\android\lib\templa ...

  4. CSS3 (一)

    属性选择器 1. E[attr^="value"]:指定了属性名,并且有属性值,属性值是以value开头的: .wrap a[href^="http://"]{ ...

  5. 在VS2010中使用MySQL-转载

    下面这篇文章进过测试,确实可以.记下来,留作记录. http://blog.sina.com.cn/s/blog_782496390100qjcu.html

  6. 谈谈Paxos一致性算法和一致性这个名词

    转自:http://www.cnblogs.com/esingchan/p/3917718.html 维基的简介:Paxos算法是莱斯利·兰伯特(Leslie Lamport,就是 LaTeX 中的& ...

  7. POJ1077 Eight —— IDA*算法

    主页面:http://www.cnblogs.com/DOLFAMINGO/p/7538588.html 代码一:像BFS那样,把棋盘数组放在结构体中. #include <iostream&g ...

  8. 转:Oracle:删除表空间

    原文:http://space.itpub.net/40239/viewspace-365948 OMF和非OMF管理的数据文件在DROP TABLESPACE时是否会自动删除,做了测试: SQL&g ...

  9. java回调机制及其实现

    1. 什么是回调函数 回调函数,顾名思义,用于回调的函数.回调函数只是一个功能片段,由用户按照回调函数调用约定来实现的一个函数.回调函数是一个工作流的一部分,由工作流来决定函数的调用(回调)时机.回调 ...

  10. 【JSOI 2009】 Count

    [题目链接] 点击打开链接 [算法] 二维树状数组 [代码] #include<bits/stdc++.h> using namespace std; #define MAXN 300 # ...