标签:des style blog http color java os io
3 10 3 1 2 3 0 1 2 100 7 3 4 5 6 7 8 9 1 2 3 4 5 6 7 10000 10 1 2 3 4 5 6 7 8 9 10 0 1 2 3 4 5 6 7 8 9
1 0 3
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; #define LL __int64 LL t , n , m , d , x , y , i , bb , aa , flag ; void gcd(LL a,LL b) { if(b == 0) { d = a ; x = 1 ; y = 0 ; } else { gcd(b,a%b); swap(x,y); x = -x ; y = -y ; y += (a/b)*x ; } return ; } LL a[30] , b[30] ; int main() { scanf("%I64d", &t); while(t--) { scanf("%I64d %I64d", &n, &m); for(i = 0 ; i < m ; i++) scanf("%I64d", &a[i]); for(i = 0 ; i < m ; i++) scanf("%I64d", &b[i]); aa = a[0] ; bb = b[0] ; flag = 1 ; for(i = 1 ; i < m ; i++) { gcd(aa,a[i]); if( (b[i]-bb)%d != 0 ) flag = 0 ; if( flag ) { x = (b[i]-bb)/d*x ; y = a[i] / d ; x = ( x%y + y )%y ; bb = bb + x * aa ; aa = aa*a[i]/d ; } } gcd(1,aa); if( bb%d != 0 ) flag = 0 ; if( flag ) { x = ( bb/d )*x ; y = aa / d ; x = (x % y + y) % y ; } if( flag == 0 || x > n ) printf("0\n"); else { if( !x ) printf("%I64d\n", (n-x)/y ); else printf("%I64d\n", (n-x)/y+1 ); } } return 0; }
hdu1573X问题(不互素的中国剩余定理),布布扣,bubuko.com
标签:des style blog http color java os io
原文地址:http://blog.csdn.net/winddreams/article/details/38472103