crt.h 988 B

123456789101112131415161718192021222324
  1. #if !defined(_crt_H)
  2. # define _crt_H (1)
  3. /*Computes the solution to a system of simple linear congruences via the
  4. Chinese Remainder Theorem.
  5. This function solves the system of equations
  6. x = a_i (mod m_i)
  7. A value x satisfies this equation if there exists an integer k such that
  8. x = a_i + k*m_i
  9. Note that under this definition, negative moduli are equivalent to positive
  10. moduli, and a modulus of 0 demands exact equality.
  11. x: Returns the solution, if it exists.
  12. Otherwise, the value is unchanged.
  13. a: An array of the a_i's.
  14. m: An array of the m_i's.
  15. These do not have to be relatively prime.
  16. n: The number of equations in the system.
  17. Return: -1 if the system is not consistent, otherwise the modulus by which
  18. the solution is unique.
  19. This modulus is the LCM of the m_i's, except in the case where one of
  20. them is 0, in which case the return value is also 0.*/
  21. int crt(int *_x,const int _a[],const int _m[],int _n);
  22. #endif