Линейные структуры данных


Download 0.6 Mb.
bet3/3
Sana10.04.2023
Hajmi0.6 Mb.
#1348692
1   2   3
Bog'liq
Kombinatorika Yusupova Janar

Binomial koeffitsentlar.

  • public class BinCoef {
  • public static void main(String[] args) {
  • int n = 1000, mod = (int)(1e9+7);
  • int[][]c = new int[n+1][n+1];
  • c[0][0] = 1;
  • for (int i = 1; i <= n; i++) {
  • c[i][0] = 1;
  • for (int j = 1; j <= n; j++) {
  • c[i][j] = (c[i-1][j-1]+c[i-1][j]) % mod;
  • }
  • }
  • }
  • }

import java.math.BigInteger;

  • import java.math.BigInteger;
  • public class Bicoef2 {
  • static long[]fac;
  • static int mod = (int) (1e9+7);
  • public static void main(String[] args) {
  • int n = (int) 1e6;
  • fac = new long[n+1];
  • fac[0] = 1;
  • for (int i = 1; i <= n; i++) {
  • fac[i] = fac[i-1] * i % mod;
  • }
  • long c = C_n_m(950412, 12367);
  • System.out.println(c);
  • System.out.println(C_n_m(10, 2));
  • }
  • private static long C_n_m(int n, int m) {
  • long res = fac[n];
  • res = res * BigInteger.valueOf(fac[m]).modInverse(BigInteger.valueOf(mod)).longValue() % mod;
  • res = res * BigInteger.valueOf(fac[n-m]).modInverse(BigInteger.valueOf(mod)).longValue() % mod;
  • return res;
  • }
  • }

E’tiboringiz uchun raxmat!


Download 0.6 Mb.

Do'stlaringiz bilan baham:
1   2   3




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling