https://minamoto.blog.luogu.org/solution-p5106

容易想到枚举质因子及其次数计算其贡献,容斥计算$\varphi(p^i)$的次方数。

 #include<cstdio>
#include<algorithm>
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
typedef long long ll;
using namespace std; const int N=,mod=1e9+;
int n,k,tot,ans,b[N],p[N]; int ksm(int a,int b,int mod){
int res=;
for (; b; a=1ll*a*a%mod,b>>=)
if (b & ) res=1ll*res*a%mod;
return res;
} void init(){
rep(i,,n){
if (!b[i]) p[++tot]=i;
for (int j=; j<=tot && i*p[j]<=n; j++){
b[i*p[j]]=;
if (i%p[j]==) break;
}
}
} int D(ll pi,ll pi1){
int s1=ksm(n-n/pi,k,mod-),s2=ksm(n-n/pi1,k,mod-);
return (s1-s2+mod-)%(mod-);
} int main(){
scanf("%d%d",&n,&k); init(); ans=;
rep(i,,tot)
for (ll t=p[i]; t<=n; t*=p[i])
ans=1ll*ans*ksm(t-t/p[i],D(t*p[i],t),mod)%mod;
printf("%d\n",ans);
return ;
}

[Luogu5106]dkw的lcm的更多相关文章

  1. P5106 dkw的lcm

    传送门 终于A了--细节真多-- 首先我们发现这是个连乘,而且\(\phi\)是个积性函数,所以我们可以考虑不同的质因子以及它的不同次数的贡献.简单来说就是把每一次的\(\phi(lcm(i_1,i_ ...

  2. [洛谷P5106]dkw的lcm:欧拉函数+容斥原理+扩展欧拉定理

    分析 考虑使用欧拉函数的计算公式化简原式,因为有: \[lcm(i_1,i_2,...,i_k)=p_1^{q_{1\ max}} \times p_2^{q_{2\ max}} \times ... ...

  3. LCM性质 + 组合数 - HDU 5407 CRB and Candies

    CRB and Candies Problem's Link Mean: 给定一个数n,求LCM(C(n,0),C(n,1),C(n,2)...C(n,n))的值,(n<=1e6). analy ...

  4. CodeBlocks及LCM应用

    以下是在开发过程中遇到的一些细节点: 1)called after throwing an instance of std::bad_alloc 此问题是由于publish(data),当中data赋 ...

  5. LCM 轻量级通信组件

    LCM和ZMQ比较 http://www.doc88.com/p-6711552253536.html 基于LCM和ZeroMQ的进程间通信研究 2.简介 LCM(Lightweight Commuc ...

  6. uva12546. LCM Pair Sum

    uva12546. LCM Pair Sum One of your friends desperately needs your help. He is working with a secret ...

  7. UVA 10791 Minimum Sum LCM(分解质因数)

    最大公倍数的最小和 题意: 给一个数字n,范围在[1,2^23-1],这个n是一系列数字的最小公倍数,这一系列数字的个数至少为2 那么找出一个序列,使他们的和最小. 分析: 一系列数字a1,a2,a3 ...

  8. LCM在Kernel中的代码分析

    lcm的分析首先是mtkfb.c 1.mtk_init中platform_driver_register(&mtkfb_driver)注册平台驱动 panelmaster_init(); DB ...

  9. Pairs Forming LCM(素因子分解)

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=109329#problem/B    全题在文末. 题意:在a,b中(a,b<=n) ...

随机推荐

  1. 树形dp(A - Anniversary party HDU - 1520 )

    题目链接:https://cn.vjudge.net/contest/277955#problem/A 题目大意:略 具体思路:刚开始接触树形dp,说一下我对这个题的初步理解吧,首先,我们从根节点开始 ...

  2. Python Dict用法

    Operation Result len(a) the number of items in a 得到字典中元素的个数 a[k] the item of a with key k 取得键K所对应的值 ...

  3. [转]std::set、自定义类型与比较函数

    转自:http://www.189works.com/article-42025-1.html 怎样在set中放入自定义类型?这个问题通过谷歌就可以得到不少答案:1.定义一个函数对象并在定义set的时 ...

  4. Ubuntu使用apt-get upgrade升级时出错

    今天在按照常规的sudo apt-get update更新软件列表后,再使用sudo apt-get upgrade升级软件时,出现了以下的错误: 正在设置 linux-image-extra-4.4 ...

  5. html5学习之canvas

    Canvas画布 1.绘图方法 ctx.moveTo(x,y) 落笔ctx.lineTo(x,y) 连线ctx.stroke() 描边 ctx.beginPath(): 开启新的图层 演示: stro ...

  6. python网络编程--线程使用threading

    一:线程使用 线程使用有两种方法,一种是直接使用,二是通过继承threading.Thread类使用 二:函数式使用 函数式:调用thread模块中的start_new_thread()函数来产生新线 ...

  7. angular可自定义的对话框,弹窗指令

    指令不明的,推荐 AngularJS指令参数详解 github地址 以下为示例代码 <!DOCTYPE html> <html lang="en" ng-app= ...

  8. new[] 到底做了什么?

    #include<iostream> #include<cstdlib> using std::cout; using std::endl; using std::hex; c ...

  9. 20165333 2016-2017-2 《Java程序设计》第1周学习总结

    20165333 2016-2017-2 <Java程序设计>第1周学习总结 教材学习内容总结 java 的地位 Java 的特点 安装JDK 系统环境的设置 Java程序的编写,编译和运 ...

  10. Asp.net Vnext 实现IView

    概述 Iview定义很简单,就是根据View上下文和TextWriter对象实现对View的呈现. 实现 实现IViewEngine public class TestViewEngine : IVi ...