传送门

当然是考虑 $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. CodeForces 754D Fedor and coupons ——(k段线段最大交集)

    还记得lyf说过k=2的方法,但是推广到k是其他的话有点麻烦.现在这里采取另外一种方法. 先将所有线段按照L进行排序,然后优先队列保存R的值,然后每次用最小的R值,和当前的L来维护答案即可.同时,如果 ...

  2. CSS效果篇--这里有你想要的CSS3漂亮的自定义Checkbox各种复选框

    在原来有一篇文章写到了<CSS效果篇--纯CSS+HTML实现checkbox的思路与实例>.这篇文章主要写各种自定义的checkbox复选框,实现如图所示的复选框: 大致的html代码都 ...

  3. VMware NAT模式设置静态IP(可上网)

    在搞电商架构的高并发高可用时,需要在VMware新建几个linux虚拟机,如果使用VMware的默认网络是自动获取的,但有时候启动虚拟机IP地址会改变,使用很不方便,所以就整理一份静态IP地址设置的方 ...

  4. android data binding jetpack I 环境配置 model-view 简单绑定

    android data binding jetpack VIII BindingConversion android data binding jetpack VII @BindingAdapter ...

  5. GitHub:Microsoft

    ylbtech-GitHub:Microsoft 1.返回顶部   2.返回顶部   3.返回顶部   4.返回顶部   5.返回顶部 1. https://github.com/microsoft ...

  6. 依赖注入框架之androidannotations

    主页: http://androidannotations.org/ 用途: 1. 使用依赖注入Views,extras,System Service,resources 2. 简化线程模型 3. 事 ...

  7. flutter Could not find the built application bundle at build/ios/iphonesimulator/Runner.app

    运行flutter run时报错 提示如下: Could not find the built application bundle at build/ios/iphonesimulator/Runn ...

  8. python 类中__call__内置函数的使用

    class F: def __call__(self, *args, **kwargs): print('执行__call__') s = F()s() 先给类创建一个对象,直接通过对象来执行,就会自 ...

  9. 前端之路(一)之W3C是什么?

    W3C 指万维网联盟(World Wide Web Consortium) W3C 最重要的工作是发展 Web 规范(称为推荐,Recommendations),这些规范描述了 Web 的通信协议(比 ...

  10. 使用gimp画线、矩形、圆等

    使用gimp画线.矩形.圆等 https://blog.csdn.net/tody_guo/article/details/7628508 2012年06月03日 19:08:47 Tody Guo  ...