Problem of hdu 1573 X, Model Linear Equations

Source: Internet
Author: User

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
    
     

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.