传送门

分析

对这个$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 选数的更多相关文章

  1. BZOJ 3930 Luogu P3172 选数 (莫比乌斯反演)

    手动博客搬家:本文发表于20180310 11:46:11, 原地址https://blog.csdn.net/suncongbo/article/details/79506484 题目链接: (Lu ...

  2. 【BZOJ-2732】集合选数 状压DP (思路题)

    2734: [HNOI2012]集合选数 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1070  Solved: 623[Submit][Statu ...

  3. CODE VS1008选数

    #include<cstdlib> #include<cstdio> #include<iostream> #include<cmath> #inclu ...

  4. BZOJ 3930: [CQOI2015]选数 递推

    3930: [CQOI2015]选数 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/pro ...

  5. bzoj 2734: [HNOI2012]集合选数 状压DP

    2734: [HNOI2012]集合选数 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 560  Solved: 321[Submit][Status ...

  6. BZOJ3930: [CQOI2015]选数

    题目:http://www.lydsy.com/JudgeOnline/problem.php?id=3930 容斥原理. 令l=(L-1)/k,r=R/k,这样找k的倍数就相当于找1的倍数. 设F[ ...

  7. 【BZOJ3930】选数(莫比乌斯反演,杜教筛)

    [BZOJ3930]选数(莫比乌斯反演,杜教筛) 题面 给定\(n,K,L,R\) 问从\(L-R\)中选出\(n\)个数,使得他们\(gcd=K\)的方案数 题解 这样想,既然\(gcd=K\),首 ...

  8. 【BZOJ2734】【HNOI2012】集合选数(状态压缩,动态规划)

    [BZOJ2734][HNOI2012]集合选数(状态压缩,动态规划) 题面 Description <集合论与图论>这门课程有一道作业题,要求同学们求出{1, 2, 3, 4, 5}的所 ...

  9. bzoj3930[CQOI2015]选数 容斥原理

    3930: [CQOI2015]选数 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 1383  Solved: 669[Submit][Status] ...

随机推荐

  1. const、define与sizeof

    一.const的用途 1.定义const常量 2.可以修饰函数的形参,返回值,以及函数体.被const修饰的内容可以受到强制保护,防止被意外修改,提高程序健壮性. const 返回值 函数返回值为 c ...

  2. jquery ajax中使用jsonp的限制(转)

    http://www.cnblogs.com/dudu/archive/2012/12/04/jquery_ajax_jsonp.html jsonp 解决的是跨域 ajax 调用的问题.为什么要跨域 ...

  3. 修改dedecms 列表页上一页 下一页 方法!

    dedecms根目录下include文件夹下:arc.listview.class.php文件! 1.简单文字替换:如 上一页替换成上页,直接替换即可! 2.文字替换成图片:上一页替换成<img ...

  4. LeetCode 336. Palindrome Pairs

    原题链接在这里:https://leetcode.com/problems/palindrome-pairs/ 题目: Given a list of unique words, find all p ...

  5. Python函数-eval()

    eval(source[, globals[, locals]]) 作用: 将字符串str当成有效的表达式来求值并返回计算结果.参数:source:一个Python表达式或函数compile()返回的 ...

  6. DOM对象和JQuery对象互转

    实现点击某一个单元格,将单元格内部的sql提交执行: <td onclick="submitSqlExecute(this)">...<span>${ctx ...

  7. Spring Boot基本配置

    本文参考javaEE开发的颠覆者SpringBoot实战第一版 基本配置 入口类和@SpringBootApplication Spring Boot通常有一个名为*Application的入口类,且 ...

  8. hl7 v2.X 版本中RSP_K23消息的构造

    RSP_K23消息有MSH, MSA, ERR, QAK, QPD, PID几个segment,其中ERR,PID为可选. 1. 当MSA有err时,ERR段填充出错的详细信息. 2. 当MSA为AA ...

  9. Python学习笔记 - MySql的使用

    一.安装MySql模块 Python2.X pip install MySQLdb Python3.X pip install pymysql 二.数据库连接接口 由于Python统一了数据库连接的接 ...

  10. 得到properties配置文件内容

    代码: 1.配置文件内容 2.文件所在项目中位置: 3.java代码: 01.得到键值对: @Test public void getProp() { Properties prop = new Pr ...