标签:contest panel clu algo iss hellip show search sea
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 6718 Accepted Submission(s): 2342
1 #include <algorithm> 2 #include <cstdio> 3 4 using namespace std; 5 6 const int N(1000000001); 7 int n,m,a[11],b[11],tot; 8 9 int exgcd(int a,int b,int &x,int &y) 10 { 11 if(!b) 12 { 13 x=1; y=0; 14 return a; 15 } 16 int ret=exgcd(b,a%b,x,y),tmp=x; 17 x=y; y=tmp-a/b*y; 18 return ret; 19 } 20 int CRT() 21 { 22 int ret=b[1]; tot=a[1]; 23 for(int i=2;i<=m;i++) 24 { 25 int x,y,tmp; 26 int c=b[i]-ret; 27 int gcd=exgcd(tot,a[i],x,y); 28 if(c%gcd) return N; 29 x=x*c/gcd; 30 int mod=a[i]/gcd; 31 x=(x%mod+mod)%mod; 32 ret+=tot*x; tot*=mod; 33 } 34 if(!ret) ret+=tot; 35 return ret; 36 } 37 38 int main() 39 { 40 int t; scanf("%d",&t); 41 for(int ans=0;t--;ans=0) 42 { 43 scanf("%d%d",&n,&m); 44 for(int i=1;i<=m;i++) scanf("%d",a+i); 45 for(int i=1;i<=m;i++) scanf("%d",b+i); 46 int tmp=CRT(); 47 for(;tmp<=n;tmp+=tot) ans++; 48 printf("%d\n",ans); 49 } 50 return 0; 51 }
标签:contest panel clu algo iss hellip show search sea
原文地址:http://www.cnblogs.com/Shy-key/p/7352287.html