链接:

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. [转帖]从入门到实践:创作一个自己的 Helm Chart

    从入门到实践:创作一个自己的 Helm Chart https://www.cnblogs.com/alisystemsoftware/p/11436469.html 自己已经搭建好了 helm 和t ...

  2. Python+request超时和重试

    Python+request超时和重试 一.什么是超时? 1.连接超时 连接超时指的是没连接上,超过指定的时间内都没有连接上,这就是连接超时.(连接时间就是httpclient发送请求的地方开始到连接 ...

  3. 提取json字符串中指定格式中的参数值

    直接上代码: import java.util.ArrayList; import java.util.regex.Matcher; import java.util.regex.Pattern; p ...

  4. spring入门一:框架整体简介

    1:spring的基本框架主要包含六大模块:DAO.ORM.AOP.JEE.WEB.CORE DAO:(Data Access Object) 数据访问对象,是一个面向对象的数据库接口. ORM:(O ...

  5. (七)Spring 配置 c3p0 连接池

    目录 在 Spring 核心配置文件中配置 c3p0 连接池 配置 JdbcTemplate 对象 在 service 层注入 userDao 在 UserDao 里面注入 JdbcTemplate ...

  6. MongoDB的复合唯一索引

    一 创建 JavaScript Shell db.room.ensureIndex({'floor':1,'num':1}) Spring Data @Data // lombok @Document ...

  7. javascript——HTML对象

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  8. excel 导入

    public static DataTable ExcelToDataTable(string fileName, string sheetName, bool isFirstRowColumn) { ...

  9. [转载]为什么jar包中能看见源码

    [转载]为什么jar包中能看见源码 这个也是我之前发现过的一个现象,只是之前没有研究过.今天正好在知乎看见,总结一下: 对于Maven或者Gradle项目,依赖的部分会自动从远程仓库下载源码 生成的j ...

  10. .NET 反射应用

    object request = null; string requestObjClassName = "命名空间" + 类型.ToString(); Type type = Ty ...