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 ...
 
随机推荐
- webpack-dev-server 导致的 invalid host header
			
这几天做的一个项目,在这个项目的 js 方面,我将其分业务和功能的拆分成模块化,然后使用 webpack 来进行打包.(第一次在公司产品中使用 webpack) 然后使用了 webpack-dev-s ...
 - 飞腾1500A 上面银河麒麟操作系统 进行远程以及添加用户的方法  linux  xrdp
			
1. 安装远程用的软件: sudo apt-get install xrdp vnc4server xbase-clients systemctl enable xrdp systemctl star ...
 - 知乎Python后端面试总结
			
一面 写个快速排序热热身,分析一下复杂度,如果不使用额外的空间,应该怎么写? 说一下Flask中g是怎么实现的,原理是什么? 说一下浏览器从输入url到页面渲染的过程,越详细越好: 了解web安全吗? ...
 - Java:关于子类继承父类接口时,由于权限没有设定的更广,出错的一个小tip
			
今天在写笔记的时候,写的地方出现了小叉叉错号. 发现问题: 这里出错了!原因是因为在子类覆写父类的方法的时候,权限不能开的比父类更低! 加了public后,纠错成功. 由于接口类型下的方法默认都是pu ...
 - 剑指offer16:输入两个单调递增的链表,合成后的链表满足单调不减规则。
			
1 题目描述 输入两个单调递增的链表,输出两个链表合成后的链表,当然我们需要合成后的链表满足单调不减规则. 2 思路与方法 迭代法:两个链表中较小的头结点作为合并后头结点,之后依次合并两个链表中较小的 ...
 - 超简单的js实现提示效果弹出以及延迟隐藏的功能
			
自动登录勾选提示效果 要求:鼠标移入显示提示信息框:鼠标离开,信息框消失,消失的效果延迟 <!DOCTYPE html> <html lang="en"> ...
 - # 滚动Hash
			
滚动Hash 假设字符串\(C=c_1*c_2*...c_m\),定义Hash函数\(H(C)=(C_1*b^{m-1}+C_2*b^{m-2}+...C_m*b^{0})mod\; h\) 从k开始 ...
 - NOIP比赛中如何加速c++的输入输出
			
NOIP比赛中如何加速c++的输入输出 在竞赛中,遇到大数据时,往往需要更快的读取方式.由于比赛中输出一般规模较小,本文只讨论输入如何加速. 现在我们生成1000000个随机数,构成1000*1000 ...
 - 代理模式与动态代理之JDK实现和CGlib实现
			
静态代理 静态代理中的代理类和委托类会实现同一接口或是派生自相同的父类. 由业务实现类.业务代理类 两部分组成.业务实现类 负责实现主要的业务方法,业务代理类负责对调用的业务方法作拦截.过滤.预处理, ...
 - 使用canal获取mysql的binlog传输给kafka,并交由logstash获取实验步骤
			
1. 实验环境 CPU:4 内存:8G ip:192.168.0.187 开启iptables防火墙 关闭selinux java >=1.5 使用yum方式安装的java,提前配置好JAVA_ ...