传送门

当然是考虑 $n$ 的每个质数 $p$ 对答案的贡献

考虑 $p^k$ 在 $[1,m]$ 中出现了几次,显然是 $\left \lfloor \frac{m}{p^k} \right \rfloor$ 次

那么对于 $p^k$ ,它目前的贡献就是 $p^{\left \lfloor \frac{m}{p^k} \right \rfloor}$ ,注意这里不是 $p^{k\left \lfloor \frac{m}{p^k} \right \rfloor}$,因为之后计算对于 $k'<k,p^{k'}$ 时的贡献会算到

然后现在问题是求 $n$ 的质因数,显然 $n$ 最多只有一个质因数大于 $\sqrt{n}$ ,那么我们只要筛 $\sqrt{n}$ 以内的质数即可

注意可能乘的时候可能爆 $long\ long$

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
#include<vector>
using namespace std;
typedef long long ull;
inline ull read()
{
ull x=,f=; char ch=getchar();
while(ch<''||ch>'') { if(ch=='-') f=-; ch=getchar(); }
while(ch>=''&&ch<='') { x=(x<<)+(x<<)+(ch^); ch=getchar(); }
return x*f;
}
const int N=1e6+,mo=1e9+;
ull n,m,ans=,pri[N],tot;
vector <ull> V;
bool not_pri[N];
inline ull ksm(ull x,ull y)
{
ull res=;
while(y) { if(y&) res=res*x%mo; x=x*x%mo; y>>=; }
return res;
}
int main()
{
n=read(),m=read();
int t=sqrt(n)+;
for(int i=;i<=t;i++)
{
if(!not_pri[i]) pri[++tot]=i;
for(int j=;j<=t;j++)
{
ull g=i*pri[j]; if(g>t) break;
not_pri[g]=; if(!(i%pri[j])) break;
}
}
for(int i=;i<=tot;i++)
if(!(n%pri[i]))
{
V.push_back(pri[i]);
while(!(n%pri[i])) n/=pri[i];
}
if(n>) V.push_back(n);
int len=V.size();
for(int i=;i<len;i++)
{
for(ull now=V[i];now<=m;now*=V[i])
{
ans=ans*ksm(V[i],m/now)%mo;
if(m/V[i]<now) break;//防止爆 unsigned long long
}
}
cout<<ans<<endl;
return ;
}

Codeforces 1228C. Primes and Multiplication的更多相关文章

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

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

  2. Primes and Multiplication

    C - Primes and Multiplication 思路:找到x的所有质数因子,用一个vector储存起来,然后对于每一个质因子来说,我们要找到它对最后的答案的贡献的大小,即要找到它在最后的乘 ...

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

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

  4. codeforces#256DIV2 D题Multiplication Table

    题目地址:http://codeforces.com/contest/448/problem/D 当时是依照找规律做的,规律倒是找出来了,可是非常麻烦非常麻烦. . 看到前几名的红名爷们3分钟就过了, ...

  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 568a//Primes or Palindromes?// Codeforces Round #315 (Div. 1)

    题意:求使pi(n)*q<=rub(n)*p成立的最大的n. 先收集所有的质数和回文数.质数好搜集.回文数奇回文就0-9的数字,然后在头尾添加一个数.在x前后加a,就是x*10+a+a*pow( ...

  7. CodeForces - 1228C(质因数分解+贡献法)

    题意 https://vjudge.net/problem/CodeForces-1228C 首先先介绍一些涉及到的定义: 定义prime(x)表示x的质因子集合.举例来说,prime(140)={2 ...

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

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

  9. Codeforces Round #589 (Div. 2)

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

随机推荐

  1. [JZOJ5400]:Repulsed(贪心+树形DP)

    题目描述 小$w$心里的火焰就要被熄灭了. 简便起见,假设小$w$的内心是一棵$n-1$条边,$n$个节点的树. 现在你要在每个节点里放一些个灭火器,每个节点可以放任意多个. 接下来每个节点都要被分配 ...

  2. django CBV模式源码执行过程

    在说CBV模式之前,先看下FBV的url配置方式: urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^xxx/', login), ur ...

  3. (十二)C语言之循环结构

  4. java实现几种常用排序:选择排序

    一.选择排序介绍 选择排序,顾名思义就是用逐个选择的方式来进行排序,逐个选择出数组中的最大(或最小)的元素,直到选择至最后一个元素.此时数组完成了排序. 二.选择排序原理分析 三.选择排序代码实现 / ...

  5. PHP安装 (结合之前的nginx安装与mysql安装组合为lnmp)

    检查安装PHP所需的lib库 yum -y install zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-de ...

  6. pid稳态控制

    https://blog.csdn.net/qq_25352981/article/details/81007075

  7. 综合开源框架之RxJava/RxAndroid

    * 一种帮助做异步的框架. 类似于 AsyncTask. 但其灵活性和扩展性远远强于前者. * 主页: https://github.com/ReactiveX/RxJava * 中文资料: * ht ...

  8. python的XML解析

    http://www.jb51.net/article/63780.htm http://www.runoob.com/python/python-xml.html http://kb.cnblogs ...

  9. JsonResponse简单使用

    一个简单的django项目 urlpatterns = [ # views.hello 是执行views中的hello函数 # name 是URL的别名 url(r'^hello/', views.h ...

  10. 【转】Apache HBase 问题排查思路

    [From]https://www.itcodemonkey.com/article/9426.html HBCK - HBCK检查什么? (1)HBase Region一致性 集群中所有region ...