HDU 5768 Lucky7-中国剩余定理+容斥原理
2016-08-01 23:43
246 查看
http://acm.hdu.edu.cn/showproblem.php?pid=5768
注意爆ll
容斥原理求一下【1,x】里有多少个满足的即可
注意爆ll
容斥原理求一下【1,x】里有多少个满足的即可
#include <cstdio> #include <cmath> #include <cstring> #include <string> #include <algorithm> #include <queue> #include <map> #include <set> #include <vector> #include <iostream> using namespace std; long long m[20],a[20],mm[20],aa[20]; void extend_Euclid(long long a, long long b, long long &x, long long &y) { if(b == 0) { x = 1; y = 0; return; } extend_Euclid(b, a % b, x, y); long long tmp = x; x = y; y = tmp - (a / b) * y; } long long CRT(long long a[],long long m[],int n,long long & M) { M = 1; long long ans = 0; for(int i=1; i<=n; i++) M *= m[i]; for(int i=1; i<=n; i++) { long long x, y; long long Mi = M / m[i]; extend_Euclid(Mi, m[i], x, y); x = (x%m[i]+m[i])%m[i]; ans = (ans + ((Mi % M) * (x % M) % M* a[i]) % M) % M; } if(ans < 0) ans += M; return ans; } int main() { //freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout); int cnt=1; int tt; scanf("%d",&tt); while (tt--) { int n; long long x,y,ans=0; scanf("%d%lld%lld",&n,&x,&y); for (int i=1; i<=n; i++) scanf("%lld%lld",&m[i],&a[i]); for (int state=0; state<(1<<n); state++) { int nn=0; for (int j=1; j<=n; j++) { if (state & (1<<(j-1))) { mm[++nn]=m[j]; aa[nn]=a[j]; } } mm[++nn]=7; aa[nn]=0; long long M; long long tmp=CRT(aa,mm,nn,M); long long numx,numy; if (x-1<tmp) numx=0; else numx=(x-tmp-1)/M+1; if (y<tmp) numy=0; else numy=(y-tmp)/M+1; long long num=numy-numx; if (nn % 2) ans+=num; else ans-=num; } printf("Case #%d: %lld\n",cnt++,ans); } return 0; }
相关文章推荐
- HDU 5768 Lucky7(中国剩余定理+容斥原理)
- HDU 5768 (Lucky7 中国剩余定理+容斥原理)
- HDU 5768 Lucky7 数论 中国剩余定理
- hdu 5768 Lucky7 容斥原理 中国剩余定理
- hdu_5768_Lucky7(中国剩余定理+容斥)
- HDU 5768 Lucky7 容斥原理+中国剩余定理(互质)
- HDU-5768-Lucky7(中国剩余定理+容斥)
- HDU 5768 Lucky7 (中国剩余定理+容斥)
- HDU 5768 Lucky7 (中国剩余定理 + 容斥 + 快速乘法)
- HDU 5768 Lucky7(2016 Multi-University Training Contest 4 -1005)——中国剩余定理 + 容斥原理
- Lucky7 HDU - 5768(中国剩余定理+容斥定理)
- HDU 5768 Lucky7 中国剩余定理
- HDU 5768 Lucky7 中国剩余定理+状压+容斥+快速乘法
- HDU-5768-Lucky7-中国剩余定律+容斥
- hdu 5768 Lucky7 中国剩余定理+容斥+快速乘
- 【中国剩余定理】【容斥原理】【快速乘法】【数论】HDU 5768 Lucky7
- 【中国剩余定理】【容斥原理】【快速乘法】【数论】HDU 5768 Lucky7
- hdu-5768 Lucky7(容斥定理+中国剩余定理)
- hdu 5768 多校4 Lucky7【crt+容斥】
- HDU 5768 Lucky7