2016多校4 hdu 5768 Lucky7 数论+容斥原理
来源:互联网 发布:网络hk什么意思 编辑:程序博客网 时间:2024/06/02 00:49
题目链接
http://acm.hdu.edu.cn/showproblem.php?pid=5768
题意
在给定范围内能够整除7并且不满足模pi等于ri的数的个数。
思路
代码
#include<cstdio>#include<cstdlib>#define LL long longLL p[20],r[20];int n;LL sum;LL powMod(LL a,int b,int mod){ LL ret=1; while(b){ if(b&1) ret=ret*a%mod; a=a*a%mod; b/=2; } return ret; }void exgcd(LL a,LL b,LL& d,LL& x,LL& y){ if(b==0){ d=a; x=1; y=0; } else{ exgcd(b,a%b,d,y,x); y-=a/b*x; } } void dfs(int i,int nu,int x,LL pp,LL rr,LL b){ //printf("%d %d %d %d %lld\n",i,nu,x,mu,b); if(nu==x){ sum+=b/pp; if((b%pp)&&(b%pp>=rr)) ++sum; return; } if(i==n) return; LL ppp=pp,rrr=rr,d,xx,yy; exgcd(ppp,p[i],d,xx,yy); xx*=(r[i]-rr)/d; xx=(xx%(p[i]/d)+p[i]/d)%(p[i]/d); rrr+=xx*ppp; ppp=ppp/d*p[i]; rrr=(rrr%ppp+ppp)%ppp; dfs(i+1,nu+1,x,ppp,rrr,b); dfs(i+1,nu,x,pp,rr,b); } LL rong(LL x){ LL s=0; for(int i=1;i<=n;++i){ sum=0; dfs(0,0,i,1,0,x); //printf("rong%d %lld\n",i,sum); if(i&1) s+=sum; else s-=sum; } //printf("%lld\n",s); return x-s; } int main(){ int t; scanf("%d",&t); for(int ca=1;ca<=t;++ca){ LL x,y; LL ansx,ansy; scanf("%d%I64d%I64d",&n,&x,&y); x=(x-1)/7; y=y/7; for(int i=0;i<n;++i){ scanf("%d%d",p+i,r+i); r[i]=powMod(7,p[i]-2,p[i])*r[i]%p[i]; } ansx=rong(x); ansy=rong(y); printf("Case #%d: %I64d\n",ca,ansy-ansx); } return 0; }
0 0
- 2016多校4 hdu 5768 Lucky7 数论+容斥原理
- 【中国剩余定理】【容斥原理】【快速乘法】【数论】HDU 5768 Lucky7
- hdu 5768 多校4 Lucky7【crt+容斥】
- hdu-5768 Lucky7 容斥
- HDU 5768 (Lucky7 中国剩余定理+容斥原理)
- HDU 5768Lucky7-中国剩余定理+容斥原理
- HDU 5768 Lucky7(中国剩余定理+容斥原理)
- hdu 5768 Lucky7 容斥原理 中国剩余定理
- HDU 5768 Lucky7(2016 Multi-University Training Contest 4 -1005)——中国剩余定理 + 容斥原理
- HDU 5768 Lucky7(CRT+容斥)
- 【HDU 5768】Lucky7(CRT+容斥)
- HDU 5768 Lucky7(容斥+同余方程组)
- HDU-5768-Lucky7(中国剩余定理+容斥)
- HDU-5768-Lucky7-中国剩余定律+容斥
- HDU 5768 Lucky7 数论 中国剩余定理
- hdu 1695 数论+容斥原理
- HDU 1695 GCD 【数论,容斥原理】
- HDU 4407 SUM 【数论,容斥原理】
- Git学习(3)
- 数组指针、二级指针
- 排序算法
- 地图要素修改
- HDOJ - 1241 Oil Deposits
- 2016多校4 hdu 5768 Lucky7 数论+容斥原理
- windbg设置条件断点
- Pandas入门笔记2-索引对象
- java算法——将字符串中的不同字符分类取出存放
- Mysql异常:com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException
- ffmepg音频重采样
- 深度剖析之 CountdownView
- 日常小结-python2.x和python3.x之间关于String的区别
- NYOJ-1058部分和问题