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的更多相关文章
- CF #589 (Div. 2)C. Primes and Multiplication 快速幂+质因数
题目链接:https://www.luogu.org/problem/CF1228C 问题可以转化为:求质数 $p$ 在 $1\sim n$ 中的每个数中的次幂之和. 因为 $p$ 是一个质数,只能由 ...
- Codeforces Round #589 (Div. 2) C - Primes and Multiplication(数学, 质数)
链接: https://codeforces.com/contest/1228/problem/C 题意: Let's introduce some definitions that will be ...
- Codeforces 1228C. Primes and Multiplication
传送门 当然是考虑 $n$ 的每个质数 $p$ 对答案的贡献 考虑 $p^k$ 在 $[1,m]$ 中出现了几次,显然是 $\left \lfloor \frac{m}{p^k} \right \rf ...
- codeforces C. Primes and Multiplication(快速幂 唯一分解定理)
题目链接:http://codeforces.com/contest/1228/problem/C 题解:给定一个函数f,g,题目有描述其中的表达式含义和两者之间的关系. 然后计算: 首先把给定的x用 ...
- 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 ...
- 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然后寻找一个数,这个数要满足的条件是它的每 ...
- 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 ...
- SPOJ4491. Primes in GCD Table(gcd(a,b)=d素数,(1<=a<=n,1<=b<=m))加强版
SPOJ4491. Primes in GCD Table Problem code: PGCD Johnny has created a table which encodes the result ...
随机推荐
- MySQL 存储引擎的类型以及选择
针对MySQL,数据最终以什么样的形式保存?以及数据保存在硬盘的什么位置? 1.MySQL的存储引擎 MySQL属于数据管理系统(DBMS),其中包括数据库,负责存储数据:还有数据库访问管理的接口系统 ...
- 24-Perl 数据库连接
1.Perl 数据库连接本章节我们将为大家介绍 Perl 数据库的连接.Perl 5 中我们可以使用 DBI 模块来连接数据库.DBI 英文全称:Database Independent Interf ...
- docker_nginx_php_mysql
https://blog.csdn.net/miwumuge/article/details/83386679 问题 1.容器内访问宿主机地址, host.docker.internal
- C#实现鼠标滚筒缩放界面的效果
elementCanvas继承UserControl 声明属性: #region 缩放属性添加 float ratio = 1.0f; public float Ratio { set { ratio ...
- centos配置LVS
LVS有三种工作模式:NAT, TUN, DR. DR是三种工作模式中性能最高的,TUN次之. 本文记录LVS/TUN和LVS/DR工作模式的配置过程. 环境: 三台CentOS 7 x64 虚拟机 ...
- Shell脚本grep命令
三剑客:grep sed awk grep:文本行过滤工具 sed: 文本行编辑器(流编辑器) awk: 报告生成器,输出格式化 grep包含三个命令: grep egrep fgrep .他们 ...
- multiple类型的select option在django后台如何取值
之前前端的select都是单选类型,在新的场景中允许用户选择多个条件, 前端的代码如下: <form action="{% url 'info:result-list' %}" ...
- 【转】sscanf函数用法实例
sscanf() - 从一个字符串中读进与指定格式相符的数据. 函数原型: Int sscanf( string str, string fmt, mixed var1, mixed var2 . ...
- linux基础—课堂随笔04_文件查找和压缩
文件查找和压缩 文件查找 1.locate 这个命令是对其生成的数据库进行遍历(生成数据库的命令:updatedb),这一特性决定了用locate查找文件速度很快,但是locate命令只能对文件进 ...
- 一键登录怎么在iOS端实现?这篇文章教会你!
在一键登录出现之前,市场上最常见的APP 注册登录方式主要有账号密码.短信验证及第三方登录.这几种方式看似常见且便捷,实则存在许多安全隐患,用户体验也相对较差.首先,短信验证码到达率低.用户操作繁琐且 ...