C - Primes and Multiplication

思路:找到x的所有质数因子,用一个vector储存起来,然后对于每一个质因子来说,我们要找到它对最后的答案的贡献的大小,即要找到它在最后的乘积中出现了多少次。

求解方法:

for(auto i:v)
{
ll cnt=0;
ll temp=n/i;
while(temp)
cnt+=temp,temp/=i;
ans=(ans*qpow(i,cnt))%mod;
}

另外,该题还需要用到快速幂的技巧。

ll qpow(ll x,ll n)
{
ll re=1;
while(n)
{
if(n&1) re=(re*x)%mod;
n>>=1,x=(x*x)%mod;
}
return re;
}

代码:

// Created by CAD on 2019/10/1.
#include <bits/stdc++.h> #define ll long long
using namespace std;
const int mod=1e9+7; ll qpow(ll x,ll n)
{
ll re=1;
while(n)
{
if(n&1) re=(re*x)%mod;
n>>=1,x=(x*x)%mod;
}
return re;
}
vector<ll> v;
int main()
{
ll n,x; cin>>x>>n;
for(ll i=2;i*i<=x;++i)
if(x%i==0)
{
v.push_back(i);
while(x%i==0)
x/=i;
}
if(x!=1) v.push_back(x);
ll ans=1;
for(auto i:v)
{
ll cnt=0;
ll temp=n/i;
while(temp)
cnt+=temp,temp/=i;
ans=(ans*qpow(i,cnt))%mod;
}
cout<<ans<<endl;
}

Primes and Multiplication的更多相关文章

  1. CF #589 (Div. 2)C. Primes and Multiplication 快速幂+质因数

    题目链接:https://www.luogu.org/problem/CF1228C 问题可以转化为:求质数 $p$ 在 $1\sim n$ 中的每个数中的次幂之和. 因为 $p$ 是一个质数,只能由 ...

  2. Codeforces Round #589 (Div. 2) C - Primes and Multiplication(数学, 质数)

    链接: https://codeforces.com/contest/1228/problem/C 题意: Let's introduce some definitions that will be ...

  3. Codeforces 1228C. Primes and Multiplication

    传送门 当然是考虑 $n$ 的每个质数 $p$ 对答案的贡献 考虑 $p^k$ 在 $[1,m]$ 中出现了几次,显然是 $\left \lfloor \frac{m}{p^k} \right \rf ...

  4. codeforces C. Primes and Multiplication(快速幂 唯一分解定理)

    题目链接:http://codeforces.com/contest/1228/problem/C 题解:给定一个函数f,g,题目有描述其中的表达式含义和两者之间的关系. 然后计算: 首先把给定的x用 ...

  5. C. Primes and Multiplication

    题目连接:https://codeforces.com/contest/1228/problem/C 题目大意:g(x,y)==y^k(其中y^k是X的最大可以整除因子) f(x,y)==g(x,p1 ...

  6. Codeforces Round #589 (Div. 2)

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

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

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

  8. SPOJ PGCD 4491. Primes in GCD Table && BZOJ 2820 YY的GCD (莫比乌斯反演)

    4491. Primes in GCD Table Problem code: PGCD Johnny has created a table which encodes the results of ...

  9. SPOJ4491. Primes in GCD Table(gcd(a,b)=d素数,(1&lt;=a&lt;=n,1&lt;=b&lt;=m))加强版

    SPOJ4491. Primes in GCD Table Problem code: PGCD Johnny has created a table which encodes the result ...

随机推荐

  1. SpringBoot 进阶

    SpringBoot 进阶 这里讲两个小方面: 表单验证 AOP 1. 表单验证 SpringBoot 中的表单验证功能步骤如下: 在 controller 类中将用 @PathVariable 和 ...

  2. 电脑主板插线方法图解_JFP1主板插线图解

    电脑主板插线方法图解_JFP1主板插线图 仔细看主板上有对应的英文标识的,一对一插就行分别是电源,复位,硬盘灯,电源灯的负极,正极

  3. BootStrape基础使用

    官网:www.bootcss.com 一. 全局css样式 栅格系统 栅格系统用于通过一系列的行(row)与列(column)的组合来创建页面布局 <!DOCTYPE html> < ...

  4. winfrom 操作Excel

    利用Aspose.Cells.dll 操作Excel,内容如下: 1.界面设计: 2.逻辑: using System; using System.Collections.Generic; using ...

  5. Idea格式化快捷键无效,没反应

    Idea格式化快捷键无效,没反应 1,关闭网易云音乐快捷键 2,修改搜狗输入法快捷键 目前本人只遇到过这两种

  6. linux递归查找目录下所有文件夹以及文件

    相对于ls或者ll,可能find在这个时候更加给力 先看我的目录结构 tree命令是查看目录的结构,而且最后会列出所有的directory的数目以及文件夹的数目...好像我们接下来要做的就没有必要了, ...

  7. tp5.1 nginx配置

    解决方案 修改fastcgi的配置文件    目录:/www/server/nginx/conf/fastcgi.conf fastcgi_param PHP_ADMIN_VALUE "op ...

  8. 【wifi移植 2】 移植wpa_supplicant

    参考文章: http://bbs.eeworld.com.cn/thread-447273-1-1.html(加精作品) 1. 下载源码 下载wpa_supplicant-2.2.tar(openss ...

  9. python中的负数取模问题(一个大坑)

    先来看一段代码 这是什么情况?为什么会出现这种结果.我们再来看看其它语言的执行结果 我们用golang.js.c分别算了一下,结果得到的结果都是一致的,但是python为啥不一样呢? 其实之所以这么做 ...

  10. less 分页显示文件内容

    1.命令功能 less 是more的增强版,可以分页显示文件内容,而且less打开文件的速度要比vi,more更快.less支持搜索功能,显示行号. 2.语法格式 less  option  file ...