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] ...
随机推荐
- 条款49:了解new-handle行为
多线程下的内存管理与单线程下是完全不同的,因为heap是一个可以被全局改动的资源,所以所有的线程都有可能去访问这一资源,这回导致很多的race_conditions. 当operator new未 ...
- 一直想写的关于tarjan算法的理解——向struct edge大佬低头
tarjan的算法精髓就是dfn[]和low[]数组 dfn[i]表示在该节点被搜索的次序(时间戳) low[i]表示i或i的子树可以追溯到的最早的栈中节点 判断有强连通分量的条件就是 dfn[i]= ...
- New Concept English three (48)
23w/m 76errors In this much-travelled world, there are still thousands of places which are inaccessi ...
- New Concept English three (46)
27w/m 66 error So great is our passion for doing things for ourselves, that we are becoming increasi ...
- c语言%.*s是什么
int i; ;i<;i++) printf("%.*s%s\n", i, " ", "########"); ; *用来指定宽度,对 ...
- LeetCode Relative Ranks
原题链接在这里:https://leetcode.com/problems/relative-ranks/#/description 题目: Given scores of N athletes, f ...
- flask之instance_path实例路径
Flask 0.8 introduces instance folders. Flask for a long time made it possible to refer to paths rela ...
- (转)通过WMI获取网卡MAC地址、硬盘序列号、主板序列号、CPU ID、BIOS序列号
最近由于项目的需要,需要在程序中获取机器的硬盘序列号和MAC地址等信息,在C#下,可以很容易的获得这些信息,但是在C++程序中感觉比较麻烦.经过百度,发现很多大虾都是通过WMI来获取这些硬件信息的,网 ...
- unix下网络编程之I/O复用(四)
首先需要了解的是select函数: select函数 #include<sys/select.h> #include<sys/time.h> int select (int m ...
- SQL简单嵌套查询与非嵌套查询的比较(MSSQL2005)
某天的工作是修复某个项目的bug,接着就发现,其sql极其混乱,有非常多的left join和in操作,还有嵌套查询(只有一个表的嵌套查询).不知道看到过哪里的资料说,嵌套查询速度慢,于是我把全部嵌套 ...