关于洛谷 C#
  • 板块灌水区
  • 楼主CleanIce
  • 当前回复8
  • 已保存回复8
  • 发布时间2023/8/13 21:52
  • 上次更新2023/11/3 04:00:21
查看原帖
关于洛谷 C#
821660
CleanIce楼主2023/8/13 21:52

用 C# 代码提交 P3807 为何 CE?

namespace Luogu {
    public class Program {
        private const int maxn = 100001;
        private static int t, n, m, p;
        private static long[] a = new long[maxn], b = new long[maxn];
        public static void Main() {
            t = int.Parse(Console.ReadLine());
            while (t-- != 0) {
                string[] res = Console.ReadLine().Split(" ");
                n = int.Parse(res[0]);
                m = int.Parse(res[1]);
                p = int.Parse(res[2]);
                a[0] = a[1] = b[0] = b[1] = 1;
                for (int i = 2; i <= n + m; i++) {
                    b[i] = b[i - 1] * i % p;
                }
                for (int i = 2; i <= n + m; i++) {
                    a[i] = (p - p / i) * a[p % i] % p;
                }
                for (int i = 2; i <= n + m; i++) {
                    a[i] = a[i - 1] * a[i] % p;
                }
                Console.WriteLine(Lucas(n + m, m));
            }
        }
        private static long Lucas(int x, int y) {
            if (x < y) {
                return 0;
            }
            else if (x < p) {
                return b[x] * a[y] * a[x - y] % p;
            } else {
                return Lucas(x / p, y / p) * Lucas(x % p, y % p) % p;
            }
        }
    }
}
2023/8/13 21:52
加载中...