Problem of hdu 1573 X, Model Linear Equations
Returns the number of X integers less than or equal to N. X mod a [0] = B [0], X mod a [1] = B [1], X mod a [2] = B [2],…, X mod a [I] = B [I],… (0 <a [I] <= 10 ).
The first line of Input data is a positive integer T, indicating that there are T groups of test data. The first behavior of each group of test data is two positive integers N, M (0 <N <= 1000,000,000, 0 <M <= 10), indicating that X is less than or equal to N, the arrays a and B have M elements. In the next two rows, each row has M positive integers, which are elements in a and B respectively. Output corresponds to each input group, and a positive integer is Output in an independent row, indicating the number of X that meets the conditions.
Sample Input
310 31 2 30 1 2100 73 4 5 6 7 8 91 2 3 4 5 6 710000 101 2 3 4 5 6 7 8 9 100 1 2 3 4 5 6 7 8 9
Sample Output
103
Model Linear Equations template question
# Include
# Include
# Include
# Include using namespace std; typedef long ll; ll ex_gcd (ll a, ll B, ll & x, ll & y) {if (a = 0 & B = 0) return-1; if (B = 0) {x = 1; y = 0; return ;} ll d = ex_gcd (B, a % B, y, x); y-= a/B * x; return d;} bool solve (int & m0, int & a0, int m, int a) {ll y, x; ll g = ex_gcd (m0, m, x, y); if (abs (a-a0) % g) return false; x * = (a-a0)/g; x % = m/g; a0 = (x * m0 + a0); m0 * = m/g; a0 % = m0; if (a0 <0) a0 + = m0; return true;} int mm [11], aa [11]; // The modulus is mm [I], the remainder is aa [I], X % mm [I] = aa [I] // X = a0 + m0 * t (0 <= a0