传送门

当然是考虑 $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. 白鹭引擎EUI做H5活动 入门篇

    前言:本学习文档的目的是为了实现h5,或者简单的h5游戏,比如说,我们要实现一个可以左右,或者上下移动的场景的h5,在场景移动的过程中,会有相应的动画或者操作,我们通过 js 也可以实现,但是为了流畅 ...

  2. RTS打卡计划第四周

    Algorithms: https://leetcode-cn.com/problems/subarray-sum-equals-k/comments/ 此问题开始考虑空间换时间,结果完全不用空间,不 ...

  3. shiro 不使用加密 解决 org.apache.shiro.authc.IncorrectCredentialsException: Submitted credentials for token [org.apache.sh

    测试本方法为失效的 报错: org.apache.shiro.authc.IncorrectCredentialsException: Submitted credentials for token ...

  4. docker基础知识普及(一)

    背景 这篇内容是之前给部门同事培训时写的文档,旨在传达一些docker相关概念,有个基本印象,当然,以下内容都来自网络,我只是个搬运工.具体操作在下篇文章中 一.什么是docker? 1. Docke ...

  5. JxBrowser开启调试模式,JxBrowser debug

    原文: 一.问题描述 像一般的浏览器都带了调试功能,按F12就能打开,在JxBrowser中如何开启调试模式了. 二.解决方法 以下代码就能开启调试模式: import com.teamdev.jxb ...

  6. 图片加载框架之fresco

    FaceBook推出的图片处理框架主页: https://github.com/facebook/fresco中文文档:http://fresco-cn.org/docs/index.html 功能 ...

  7. 数据库开源框架之ormlite

    主页: http://ormlite.com/ 配置: 添加以下依赖 * compile 'com.j256.ormlite:ormlite-android:4.48' * compile 'com. ...

  8. ip地址后面的斜杠24

    ip地址后面的斜杠24表示掩码位是24位的,即用32位二进制表示的子网掩码中有连续的24个“1”:11111111 11111111 11111111 00000000,将其转化为十进制,就是:255 ...

  9. Setup Python 开发环境和IPython的基本使用

    目录 目录 前言 软件准备 Python交互式Shell 为Python Shell添加补全功能 IPython-400 IPython功能和特性基础 可直接使用部分的Bash指令 别名alias语法 ...

  10. win + T 快捷键

    和 alt + tab 不同,win + T会在 在任务栏间的程序间进行switch