Codeforces Round #589 (Div. 2) C - Primes and Multiplication(数学, 质数)
链接:
https://codeforces.com/contest/1228/problem/C
题意:
Let's introduce some definitions that will be needed later.
Let prime(x) be the set of prime divisors of x. For example, prime(140)={2,5,7}, prime(169)={13}.
Let g(x,p) be the maximum possible integer pk where k is an integer such that x is divisible by pk. For example:
g(45,3)=9 (45 is divisible by 32=9 but not divisible by 33=27),
g(63,7)=7 (63 is divisible by 71=7 but not divisible by 72=49).
Let f(x,y) be the product of g(y,p) for all p in prime(x). For example:
f(30,70)=g(70,2)⋅g(70,3)⋅g(70,5)=21⋅30⋅51=10,
f(525,63)=g(63,3)⋅g(63,5)⋅g(63,7)=32⋅50⋅71=63.
You have integers x and n. Calculate f(x,1)⋅f(x,2)⋅…⋅f(x,n)mod(109+7).
思路:
对于x的每个质约数, 计算其在n!内的乘积总和.
先得到x的质约数, 对于每个质数p, 其在n!内存在n/p^1, n/p^2....因为算的时候不断累加后面, 所有算一边即可.
快速幂优化.
代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MOD = 1e9+7;
vector<int> Pri;
void Init(LL val)
{
for (LL i = 2;i*i <= val;i++)
{
if (val%i == 0)
Pri.push_back(i);
while (val%i == 0)
val /= i;
}
if (val != 1)
Pri.push_back(val);
}
LL Cal(LL val, int p)
{
//素数p在val的阶乘下的次方贡献
LL cnt = 0;
while (val)
{
cnt += val/p;
val /= p;
}
return cnt;
}
LL QucikMi(LL a, LL b)
{
LL res = 1;
while (b)
{
if (b&1)
res = (res*a)%MOD;
a = (a*a)%MOD;
b >>= 1;
}
return res;
}
int main()
{
LL x, n;
cin >> x >> n;
Init(x);
LL res = 1;
for (int i = 0;i < Pri.size();i++)
{
LL cnt = Cal(n, Pri[i]);
res = (res*(QucikMi(Pri[i], cnt)))%MOD;
}
cout << res%MOD << endl;
return 0;
}
Codeforces Round #589 (Div. 2) C - Primes and Multiplication(数学, 质数)的更多相关文章
- Codeforces Round #589 (Div. 2)-E. Another Filling the Grid-容斥定理
Codeforces Round #589 (Div. 2)-E. Another Filling the Grid-容斥定理 [Problem Description] 在\(n\times n\) ...
- Codeforces Round #368 (Div. 2) C. Pythagorean Triples(数学)
Pythagorean Triples 题目链接: http://codeforces.com/contest/707/problem/C Description Katya studies in a ...
- Codeforces Round #622 (Div. 2) B. Different Rules(数学)
Codeforces Round #622 (Div. 2) B. Different Rules 题意: 你在参加一个比赛,最终按两场分赛的排名之和排名,每场分赛中不存在名次并列,给出参赛人数 n ...
- Codeforces Round #589 (Div. 2)
目录 Contest Info Solutions A. Distinct Digits B. Filling the Grid C. Primes and Multiplication D. Com ...
- Codeforces Round #589 (Div. 2) (e、f没写)
https://codeforces.com/contest/1228/problem/A A. Distinct Digits 超级简单嘻嘻,给你一个l和r然后寻找一个数,这个数要满足的条件是它的每 ...
- Codeforces Round #284 (Div. 2)A B C 模拟 数学
A. Watching a movie time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #315 (Div. 1) A. Primes or Palindromes? 暴力
A. Primes or Palindromes?Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=3261 ...
- Codeforces Round #315 (Div. 2) C. Primes or Palindromes? 暴力
C. Primes or Palindromes? time limit per test 3 seconds memory limit per test 256 megabytes input st ...
- Codeforces Round 589 (Div. 2) 题解
Is that a kind of fetishism? No, he is objectively a god. 见识了一把 Mcdic 究竟出题有多神. (虽然感觉还是吹过头了) 开了场 Virt ...
随机推荐
- Spark和Scala当中的collect方法的用法和例子
[学习笔记] collect: 收集一个弹性分布式数据集的所有元素到一个数组中,这样便于我们观察,毕竟分布式数据集比较抽象.Spark的collect方法,是Action类型的一个算子,会从远程集群拉 ...
- 【LOJ】#3096. 「SNOI2019」数论
LOJ#3096. 「SNOI2019」数论 如果\(P > Q\)我们把\(P\)和\(Q\)换一下,现在默认\(P < Q\) 这个时候每个合法的\(a_i\)都可以直接落到\(Q\) ...
- 【HDU】6242-Geometry Problem
今天忽然心血来潮打开牛客网尝试了一下一站到底 前四道题都是不到二十分钟切完,然后第五道来了道计算几何 我也不会啊,于是就觉得大力随机也许可行 然鹅被精度卡到崩溃 后来我才知道 保证有解,是保证你的精度 ...
- Thinking In Java 4th Chap2 一切都是对象
对基本数据类型的初始化有二: 1.String s="asdf"; 2.String s=new String("asdf"); 可能的存储区域: 寄存器(不可 ...
- celery(芹菜) 异步任务 定时任务 周期任务
什么是celery Celery是一个简单.灵活且可靠的,处理大量消息的分布式系统 专注于实时处理的异步任务队列 同时也支持任务调度 celery架构 celery的架构由三部分组成,消息中间件(me ...
- Python【条件判断】
单向判断ifif xxx: #冒号 #条件 print(xxx) #缩进是四个空格或一个Tab键#被缩进的内容(print()函数)和if条件语句组成了一个代码块(一个整体)————————————— ...
- Python 运算符与数据类型
Python 的创始人为吉多·范罗苏姆(Guido van Rossum).1989年的圣诞节期间,吉多·范罗苏姆为了在阿姆斯特丹打发时间,决心开发一个新的脚本解释程序,作为ABC语言的一种继承.Py ...
- APP安全测试之安装/卸载/更新测试
在app测试中,有个不可忽视的测试方向,就是安装.卸载和更新,有很多人问到了这个问题,我就在这里做了一个总结,有补充的请留言哦 安装 1.正常安装测试,检查是否安装成功. 2.APP版本覆盖测试.例如 ...
- ReLU、LReLU、PReLU、CReLU、ELU、SELU
ReLU.LReLU.PReLU.CReLU.ELU.SELU 2018年01月22日 22:25:34 luxiaohai的学习专栏 阅读数 28218更多 分类专栏: 深度学习 版权声明:本文 ...
- HTTP协议探究(三):HTTPS
一 复习与目标 1 复习 代理:转发通信数据(一般协议不变,作为中间人,可对报文进行过滤修改) 网关:转发通信数据(协议改变,作为资源拥有者) 隧道:转发通信数据(协议不变,作为管道,不对报文进行过滤 ...