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. HTML——b i del a p img h1 h2 h3 h4 h5 h6 hr ol ul 标签的使用方法详解

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

  2. 如何使用Navicat 创建一个SqlServer定时任务

    因为网上资料不全,所以自己琢磨了一上午,终于弄出来了,记录一下. step1: 右击[函数]选择[新建函数]添加一个存储过程 step2: 选择[过程],点击下一步直至完成,然后编辑存储过程,保存 s ...

  3. Ruby 参考教程

    Ruby 参考教程 https://www.ruby-lang.org/zh_cn/documentation/ http://ruby-doc.org/docs/ https://ruby-chin ...

  4. 小白学 Python 爬虫(25):爬取股票信息

    人生苦短,我用 Python 前文传送门: 小白学 Python 爬虫(1):开篇 小白学 Python 爬虫(2):前置准备(一)基本类库的安装 小白学 Python 爬虫(3):前置准备(二)Li ...

  5. VC++ warning C4819 的解决方法(转)

    编译VC++程序的时候出现如下提示警告: warning C4819: The file contains a character that cannot be represented in the ...

  6. O057、Delete Volume 操作

    参考https://www.cnblogs.com/CloudMan6/p/5648665.html   状态为Available 的volume 才能够被delete,如果volume当前已经被at ...

  7. docker之常见错误

    1. docker run -d --name showdoc -p 4999:80 -v /showdoc_data/html:/var/www/html/ star7th/showdoc WARN ...

  8. vue.js项目开发实战笔记001——准备工作

    1,Vue.js 是一套构建用户界面的渐进式框架. 2,Vue.js 是由尤雨溪开发出的,最早发布于2014年2月. 3,引用vue.js地址一CDN: <script src="ht ...

  9. .NET中跨线程访问winform控件的方法

    1 第一种方式 MethodInvoker invoker = () => { richTextBox1.AppendText(_ClientSocketModelConnectedEvent. ...

  10. 通过Callable接口实现多线程

    一.通过Callable接口实现多线程 c.实现Callable重写call方法 实现Callable和实现Runnable类似,但是功能更强大,具体表现在 a.可以在任务结束后提供一个返回值,Run ...