链接:

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(数学, 质数)的更多相关文章

  1. 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\) ...

  2. Codeforces Round #368 (Div. 2) C. Pythagorean Triples(数学)

    Pythagorean Triples 题目链接: http://codeforces.com/contest/707/problem/C Description Katya studies in a ...

  3. Codeforces Round #622 (Div. 2) B. Different Rules(数学)

    Codeforces Round #622 (Div. 2) B. Different Rules 题意: 你在参加一个比赛,最终按两场分赛的排名之和排名,每场分赛中不存在名次并列,给出参赛人数 n ...

  4. Codeforces Round #589 (Div. 2)

    目录 Contest Info Solutions A. Distinct Digits B. Filling the Grid C. Primes and Multiplication D. Com ...

  5. Codeforces Round #589 (Div. 2) (e、f没写)

    https://codeforces.com/contest/1228/problem/A A. Distinct Digits 超级简单嘻嘻,给你一个l和r然后寻找一个数,这个数要满足的条件是它的每 ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. Codeforces Round 589 (Div. 2) 题解

    Is that a kind of fetishism? No, he is objectively a god. 见识了一把 Mcdic 究竟出题有多神. (虽然感觉还是吹过头了) 开了场 Virt ...

随机推荐

  1. Javaweb入门 JDBC第一天

    JDBC的定义和作用 DBC(Java DataBase Connectivity) Java数据库连接, 其实就是利用Java语言/程序连接并访问数据库的一门技术. 之前我们可以通过cmd或者nav ...

  2. phpstorm右侧边栏怎么打开?

    开启PHPstorm右侧边栏的方法: 一般phpstorm默认只能打开10个文件,超过就隐藏了,想要打开更多:

  3. oracle用户解锁,rename管理

    ---查看命令:用户默认表空间 SYS@ACE >select username,default_tablespace,temporary_tablespace,created from dba ...

  4. java大框架

    本文章,列出了一些程序员需要学习的技术和知识点,有些技术和知识点没有写道,欢迎大家进行修改和补充,有些技术公司用到,大家需要先学习,有些技术和知识点过时,大家可以了解.本人笔记连接[[http://2 ...

  5. TypeScript入门六:TypeScript的泛型

    泛型函数 泛型类 一.泛型函数 在泛型函数之前,先简单的描述一下泛型,将变量定义成泛型可以在使用变量时来决定它的类型.什么意思呢?假如现在有一个函数,可能出现参数和返回值出现多种情况的现象,只有在调用 ...

  6. JavaScript笔记(5)

    1.DOM操作 常用的DOM操作 document.getElementById(id); //返回指定id的元素,通用 document.getElementsByTagName(tagName); ...

  7. PLSQL导入导出数据库

    使用sql脚本和plsql完成数据库的导入导出 1. 准备数据库创建脚本 [SQL] 创建数据库表空间: 格式:create tablespace 表空间名 datafile ‘数据文件位置及名称’ ...

  8. Spring web.xml详解

    web.xml文件是Java Web项目中的一个配置文件,主要用于配置欢迎页.Filter.Listener.Servlet等,但并不是必须的,一个Java Web项目没有web.xml文件也是照样能 ...

  9. JavaSpring【一、概述】

    主要内容 JavaSpring[一.概述] JavaSpring[二.IOC] JavaSpring[三.Bean] JavaSpring[四.Bean管理注解实现] JavaSpring[五.AOP ...

  10. 用window.showModalDialog()打开的页面Request.UrlReferrer为null

    今天在解决一个问题,怎么也找不到解决方案.我的一个窗体是IE通过window.showModalDialog()打开的,但为了防止用户手工输的地址,所以我需要判断是通过别的页面调整获得,用Reques ...