C# ACM poj1006

中国剩余定理

public static void acm1006(int a, int b, int c, int d)

        {

            int z = 28 * 33;

            int y = 23 * 33;

            int x = 23 * 28;

            int w = 23 * 28 * 33;

            int n = Acm1006Unit(z, 23) * z;

            int m = Acm1006Unit(y, 28) * y;

            int o = Acm1006Unit(x, 33) * x;

            int r = (n * a + m * b + o * c - d) % w;

            Console.WriteLine(r);

        }

        public static int Acm1006Unit(int a, int b)

        {

            int n = 1;

            while ((a * n) % b != 1)

                n++;

            return n;

        }

 

你可能感兴趣的:(ACM)