[反演] 2017 计蒜之道 复赛 A. 阿里云秘钥池
来源:互联网 发布:手机三维绘图软件 编辑:程序博客网 时间:2024/05/17 04:41
不错的题。
我们就是要解决小于n的合法的数有几个。有个套路就是考虑最高的和
推式子就好啦
这样就可以可以每层
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;typedef long long LL;const int maxn=100005,N=100000;int p[maxn],mu[maxn];bool vis[maxn];void get_mu(){ mu[1]=1; for(int i=2;i<=N;i++){ if(!vis[i]) p[++p[0]]=i, mu[i]=-1; for(int j=1;j<=p[0]&&(LL)i*p[j]<=N;j++){ vis[i*p[j]]=true; if(i%p[j]==0){ mu[i*p[j]]=0; break; } mu[i*p[j]]=-mu[i]; } }}int _test,P;LL f[70][maxn];int tem[70];inline int gcd(int x,int y){ return y==0?x:gcd(y,x%y); }LL Calc(LL n){ memset(tem,0,sizeof(tem)); LL _n=n; do tem[++tem[0]]=_n%P, _n/=P; while(_n); for(int i=0;i<=tem[0];i++) for(int j=0;j<=P;j++) f[i][j]=0; for(int i=1;i<=P-1;i++) f[1][i]=1; for(int i=1;i<=P-1;i++){ LL _g=0; for(int j=1;(LL)i*j<=P-1;j++) _g+=f[1][i*j]; for(int j=1;(LL)i*j<=P-1;j++) f[2][i*j]+=_g*mu[i]; } for(int k=2;k<=tem[0];k++){ for(int i=1;i<=P-1;i++){ LL _g=0; for(int j=1;(LL)i*j<=P-1;j++) _g+=f[k][i*j]; for(int j=1;(LL)i*j<=P-1;j++) f[k+1][i*j]+=_g*mu[i]; } } LL res=0; for(int i=1;i<=tem[0]-1;i++) for(int j=1;j<=P-1;j++) res+=f[i][j]; for(int i=tem[0];i>=1;i--){ for(int j=1;j<=tem[i]-1;j++) if(i==tem[0]||gcd(tem[i+1],j)==1) res+=f[i][j]; if((tem[0]>i&&gcd(tem[i+1],tem[i])!=1)||tem[i]==0) break; } return res;} int main(){ freopen("jskA.in","r",stdin); freopen("jskA.out","w",stdout); get_mu(); scanf("%d",&_test); while(_test--){ LL L,R; scanf("%lld%lld%d",&L,&R,&P); printf("%lld\n",Calc(R+1)-Calc(L)); } return 0;}
阅读全文
0 0
- [反演] 2017 计蒜之道 复赛 A. 阿里云秘钥池
- [数位DP 莫比乌斯反演] 2017 计蒜之道 复赛 A. 阿里云秘钥池
- 【莫比乌斯反演+数位DP】2017 计蒜之道 复赛 A.阿里云秘钥池
- 【数位DP+莫比乌斯函数】2017计蒜之道复赛A[阿里云秘钥池]题解
- 【计蒜客】「2017 计蒜之道 复赛」A.阿里云秘钥池 数位DP+莫比乌斯函数
- 2016 计蒜之道 复赛 A
- 2017计蒜之道 复赛 BDF
- 2017 计蒜之道 复赛 题解
- [计蒜之道 复赛2017] 题解 (只有 A,E 两题)
- 2017计蒜之道复赛-Windows 画图
- 2017计蒜之道程序设计大赛复赛题解
- 2017 计蒜之道 复赛 <状压DP+最短路>
- 2017 计蒜之道 复赛 腾讯消消乐
- 计蒜客-2017 计蒜之道 复赛-B-Windows 画图
- 计蒜之道复赛A题 百度地图的实时路况(分治+floyd)
- 2016计蒜之道 复赛 A. 百度地图的实时路况(cdq分治+floyd)
- 算法:分治+floyd_计蒜之道复赛A题 百度地图的实时路况
- 计蒜之道 2016复赛A 百度地图的实时路况 [floyd+分治]【图论】
- Sublime text 3搭建Python开发环境
- 10.3 NOIP模拟赛 DP + 最小生成树 + 容斥
- 【C++】实现双向循环链表
- leecode 169. Majority Element(C语言,快速排序,堆排序,各类排序算法复杂度比较)22
- 基于TensorFlow实现Skip-Gram模型
- [反演] 2017 计蒜之道 复赛 A. 阿里云秘钥池
- URAL 1009|URAL 1012|URAL 1013|K-based Numbers|高精度|动态规划
- 用construct 2来做一个射击小游戏吧ヾ(o´∀`o)ノ
- 51Nod 1085背包问题(dp)
- poj 3177 Redundant Paths 边-双连通分量
- pata1039(输出格式很重要,多一个空格就完蛋!)
- Bootstrap学习
- [最短路] 2017 计蒜之道 复赛 D. 百度地图导航
- 杂项 数据竞赛