p3172 选数
分析

对这个$f(k)$整除分块,用杜教筛搞出$\mu$的部分然后另一部分快速幂即可
代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
const int N = 5e6;
const int mod = 1e9+;
int p[N+],mu[N+];
bool is[N+];
map<int,int>MU;
inline void init(){
int i,j,cnt=;
mu[]=;
for(i=;i<=N;i++){
if(!is[i])p[++cnt]=i,mu[i]=-;
for(j=;j<=cnt,i*p[j]<=N;j++){
is[p[j]*i]=;
if(i%p[j]==){
mu[p[j]*i]=;
break;
}
mu[p[j]*i]=-mu[i];
}
}
for(i=;i<=N;i++)mu[i]=(mu[i]+mu[i-]+mod)%mod;
}
inline int go(int x){
if(x<=N)return mu[x];
if(MU[x])return MU[x];
int res=,le=,ri;
for(;le<=x;le=ri+){
ri=x/(x/le);
res=(res-(long long)(ri-le+)*go(x/le)%mod+mod)%mod;
}
return MU[x]=res;
}
inline int pw(int x,int p){
int res=;
while(p){
if(p&)res=(long long)res*x%mod;
x=(long long)x*x%mod;
p>>=;
}
return res;
}
int main(){
int n,m,p,k,L,R,le=,ri,Ans=;
scanf("%d%d%d%d",&p,&k,&L,&R);
n=R/k,m=(L-)/k;
init();
for(;le<=n;le=ri+){
if(m/le)ri=min(n/(n/le),m/(m/le));
else ri=n/(n/le);
Ans=(Ans+(long long)(go(ri)-go(le-)+mod)%mod*pw(n/le-m/le,p)%mod)%mod;
}
printf("%d\n",Ans);
return ;
}
p3172 选数的更多相关文章
- BZOJ 3930 Luogu P3172 选数 (莫比乌斯反演)
手动博客搬家:本文发表于20180310 11:46:11, 原地址https://blog.csdn.net/suncongbo/article/details/79506484 题目链接: (Lu ...
- 【BZOJ-2732】集合选数 状压DP (思路题)
2734: [HNOI2012]集合选数 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1070 Solved: 623[Submit][Statu ...
- CODE VS1008选数
#include<cstdlib> #include<cstdio> #include<iostream> #include<cmath> #inclu ...
- BZOJ 3930: [CQOI2015]选数 递推
3930: [CQOI2015]选数 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/pro ...
- bzoj 2734: [HNOI2012]集合选数 状压DP
2734: [HNOI2012]集合选数 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 560 Solved: 321[Submit][Status ...
- BZOJ3930: [CQOI2015]选数
题目:http://www.lydsy.com/JudgeOnline/problem.php?id=3930 容斥原理. 令l=(L-1)/k,r=R/k,这样找k的倍数就相当于找1的倍数. 设F[ ...
- 【BZOJ3930】选数(莫比乌斯反演,杜教筛)
[BZOJ3930]选数(莫比乌斯反演,杜教筛) 题面 给定\(n,K,L,R\) 问从\(L-R\)中选出\(n\)个数,使得他们\(gcd=K\)的方案数 题解 这样想,既然\(gcd=K\),首 ...
- 【BZOJ2734】【HNOI2012】集合选数(状态压缩,动态规划)
[BZOJ2734][HNOI2012]集合选数(状态压缩,动态规划) 题面 Description <集合论与图论>这门课程有一道作业题,要求同学们求出{1, 2, 3, 4, 5}的所 ...
- bzoj3930[CQOI2015]选数 容斥原理
3930: [CQOI2015]选数 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 1383 Solved: 669[Submit][Status] ...
随机推荐
- Senior Manufacturing Technical Manager
Job Description As a Manufacturing Technical Manager, you will be responsible for bringing new produ ...
- bzoj 5016 一个简单的询问
THUWC 考了莫队(这个应该可以说吧) 然而不会莫队,签到失败,所以找到了一道长得差不多的题写一写 为什么这么长时间都没有发现这道题(半恼 给你一个长度为N的序列ai,1≤i≤N和q组询问,每组询问 ...
- POJ - 3150 :Cellular Automaton(特殊的矩阵,降维优化)
A cellular automaton is a collection of cells on a grid of specified shape that evolves through a nu ...
- Flea
It is known that fleas in Berland can jump only vertically and horizontally, and the length of the j ...
- gulp之文件合并以及整合html中的script和link
gulp的文件合并,也就是将多个js或css文件合并为一个的插件是:gulp-concat gulp将html中的多个<script>或<link>合并为一个的插件是:gulp ...
- Python collections系列之有序字典
有序字典(orderedDict ) orderdDict是对字典类型的补充,他记住了字典元素添加的顺序 1.创建一个有序字典 import collections dic = collections ...
- 用Json Template在Azure上创建Cisco CSR路由器
Azure的ARM模式可以通过Json的模板创建VM.本文以Cisco的CSR的image为例,介绍如何用Json的创建VM. 一.Cisco CSR的Image 首先把Cisco CSR的image ...
- PCIe相关的操作命令
1.lspci --显示列举系统目前的pcie设备 43:00.0 Class 0004: Device 104c:b800 (rev 01) //netra设备 设备编号 ...
- (转)C# 特性(Attribute)详细介绍
本文转载自:http://www.cnblogs.com/luckdv/articles/1682488.html 1.什么是Atrribute 首先,我们肯定Attribute是一个类,下面是msd ...
- 摘之知乎网友...PHYTIN学习
作者:东瓜王链接:https://www.zhihu.com/question/19593179/answer/23746083来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明 ...