Dados tres enteros A, X y n. La tarea es encontrar el término medio en la serie de expansión binomial.
Ejemplos:
Input : A = 1, X = 1, n = 6 Output : MiddleTerm = 20 Input : A = 2, X = 4, n = 7 Output : MiddleTerm1 = 35840, MiddleTerm2 = 71680
Acercarse
(A + X) n = n C 0 A n X 0 + n C 1 A n-1 X 1 + n C 2 A n-2 X 2 + ……… + n C n-1 A 1 X n-1 + n C n A 0 X n
El número total de términos en la expansión binomial de (A + X) n es (n + 1).
El término general en desarrollo binomial viene dado por:
T r+1 = nC r A n-r X r
Si n es un número par:
Sea m el término medio de la serie de expansión binomial, entonces
n = 2m
m = n / 2
Sabemos que habrá n + 1 término, entonces,
n + 1 = 2m + 1
En este caso, la voluntad sólo tiene un término medio. Este término medio es (m + 1) el término th .
Por lo tanto, el término medio
T m+1 = n C m A n-m X m
si n es un número impar:
Sea m el término medio de la serie de expansión binomial, luego
sea n = 2m + 1
m = (n-1) / 2
número de términos = n + 1 = 2m + 1 + 1 = 2m + 2
En este caso habrá dos términos medios. Estos términos medios serán (m + 1) th y (m + 2) th term.
Por lo tanto, los términos medios son:
T m+1 = n C (n-1)/2 A (n+1)/2 X (n-1)/2
T m+2 = n C (n+1)/ 2 A (n-1)/2 X (n+1)/2
C++
// C++ program to find the middle term // in binomial expansion series. #include <bits/stdc++.h> using namespace std; // function to calculate // factorial of a number int factorial(int n) { int fact = 1; for (int i = 1; i <= n; i++) fact *= i; return fact; } // Function to find middle term in // binomial expansion series. void findMiddleTerm(int A, int X, int n) { int i, j, aPow, xPow; float middleTerm1, middleTerm2; if (n % 2 == 0) { // If n is even // calculating the middle term i = n / 2; // calculating the value of A to // the power k and X to the power k aPow = (int)pow(A, n - i); xPow = (int)pow(X, i); middleTerm1 = ((float)factorial(n) / (factorial(n - i) * factorial(i))) * aPow * xPow; cout << "MiddleTerm = " << middleTerm1 << endl; } else { // If n is odd // calculating the middle term i = (n - 1) / 2; j = (n + 1) / 2; // calculating the value of A to the // power k and X to the power k aPow = (int)pow(A, n - i); xPow = (int)pow(X, i); middleTerm1 = ((float)factorial(n) / (factorial(n - i) * factorial(i))) * aPow * xPow; // calculating the value of A to the // power k and X to the power k aPow = (int)pow(A, n - j); xPow = (int)pow(X, j); middleTerm2 = ((float)factorial(n) / (factorial(n - j) * factorial(j))) * aPow * xPow; cout << "MiddleTerm1 = " << middleTerm1 << endl; cout << "MiddleTerm2 = " << middleTerm2 << endl; } } // Driver code int main() { int n = 5, A = 2, X = 3; // function call findMiddleTerm(A, X, n); return 0; }
Java
// Java program to find the middle term // in binomial expansion series. import java.math.*; class GFG { // function to calculate factorial // of a number static int factorial(int n) { int fact = 1, i; if (n == 0) return 1; for (i = 1; i <= n; i++) fact *= i; return fact; } // Function to find middle term in // binomial expansion series. static void findmiddle(int A, int X, int n) { int i, j, aPow, xPow; float middleTerm1, middleTerm2; if (n % 2 == 0) { // If n is even // calculating the middle term i = n / 2; // calculating the value of A to // the power k and X to the power k aPow = (int)Math.pow(A, n - i); xPow = (int)Math.pow(X, i); middleTerm1 = ((float)factorial(n) / (factorial(n - i) * factorial(i))) * aPow * xPow; System.out.println("MiddleTerm = " + middleTerm1); } else { // If n is odd // calculating the middle term i = (n - 1) / 2; j = (n + 1) / 2; // calculating the value of A to the // power k and X to the power k aPow = (int)Math.pow(A, n - i); xPow = (int)Math.pow(X, i); middleTerm1 = ((float)factorial(n) / (factorial(n - i) * factorial(i))) * aPow * xPow; // calculating the value of A to the // power k and X to the power k aPow = (int)Math.pow(A, n - j); xPow = (int)Math.pow(X, j); middleTerm2 = ((float)factorial(n) / (factorial(n - j) * factorial(j))) * aPow * xPow; System.out.println("MiddleTerm1 = " + middleTerm1); System.out.println("MiddleTerm2 = " + middleTerm2); } } // Driver code public static void main(String[] args) { int n = 6, A = 2, X = 4; // calling the function findmiddle(A, X, n); } }
Python3
# Python3 program to find the middle term # in binomial expansion series. import math # function to calculate # factorial of a number def factorial(n) : fact = 1 for i in range(1, n+1) : fact = fact * i return fact; # Function to find middle term in # binomial expansion series. def findMiddleTerm(A, X, n) : if (n % 2 == 0) : # If n is even # calculating the middle term i = int(n / 2) # calculating the value of A to # the power k and X to the power k aPow = int(math.pow(A, n - i)) xPow = int(math.pow(X, i)) middleTerm1 = ((math.factorial(n) / (math.factorial(n - i) * math.factorial(i))) * aPow * xPow) print ("MiddleTerm = {}" . format(middleTerm1)) else : # If n is odd # calculating the middle term i = int((n - 1) / 2) j = int((n + 1) / 2) # calculating the value of A to the # power k and X to the power k aPow = int(math.pow(A, n - i)) xPow = int(math.pow(X, i)) middleTerm1 = ((math.factorial(n) / (math.factorial(n - i) * math.factorial(i))) * aPow * xPow) # calculating the value of A to the # power k and X to the power k aPow = int(math.pow(A, n - j)) xPow = int(math.pow(X, j)) middleTerm2 = ((math.factorial(n) / (math.factorial(n - j) * math.factorial(j))) * aPow * xPow) print ("MiddleTerm1 = {}" . format(int(middleTerm1))) print ("MiddleTerm2 = {}" . format(int(middleTerm2))) # Driver code n = 5 A = 2 X = 3 # function call findMiddleTerm(A, X, n) # This code is contributed by # manishshaw1.
C#
// C# program to find the middle term // in binomial expansion series. using System; class GFG { // function to calculate factorial // of a number static int factorial(int n) { int fact = 1, i; if (n == 0) return 1; for (i = 1; i <= n; i++) fact *= i; return fact; } // Function to find middle term in // binomial expansion series. static void findmiddle(int A, int X, int n) { int i, j, aPow, xPow; float middleTerm1, middleTerm2; if (n % 2 == 0) { // If n is even // calculating the middle term i = n / 2; // calculating the value of A to // the power k and X to the power k aPow = (int)Math.Pow(A, n - i); xPow = (int)Math.Pow(X, i); middleTerm1 = ((float)factorial(n) / (factorial(n - i) * factorial(i))) * aPow * xPow; Console.WriteLine("MiddleTerm = " + middleTerm1); } else { // If n is odd // calculating the middle term i = (n - 1) / 2; j = (n + 1) / 2; // calculating the value of A to the // power k and X to the power k aPow = (int)Math.Pow(A, n - i); xPow = (int)Math.Pow(X, i); middleTerm1 = ((float)factorial(n) / (factorial(n - i) * factorial(i))) * aPow * xPow; // calculating the value of A to the // power k and X to the power k aPow = (int)Math.Pow(A, n - j); xPow = (int)Math.Pow(X, j); middleTerm2 = ((float)factorial(n) / (factorial(n - j) * factorial(j))) * aPow * xPow; Console.WriteLine("MiddleTerm1 = " + middleTerm1); Console.WriteLine("MiddleTerm2 = " + middleTerm2); } } // Driver code public static void Main() { int n = 5, A = 2, X = 3; // calling the function findmiddle(A, X, n); } } // This code is contributed by anuj_67.
PHP
<?php // PHP program to find the middle term // in binomial expansion series. // function to calculate // factorial of a number function factorial(int $n) { $fact = 1; for($i = 1; $i <= $n; $i++) $fact *= $i; return $fact; } // Function to find middle term in // binomial expansion series. function findMiddleTerm($A, $X, $n) { $i; $j; $aPow; $xPow; $middleTerm1; $middleTerm2; if ($n % 2 == 0) { // If n is even // calculating the middle term $i = $n / 2; // calculating the value of A to // the power k and X to the power k $aPow = pow($A, $n - i); $xPow = pow($X, $i); $middleTerm1 = $factorial($n) / (factorial($n - $i) * factorial($i)) * $aPow * $xPow; echo "MiddleTerm = ","\n", $middleTerm1 ; } else { // If n is odd // calculating the middle term $i = ($n - 1) / 2; $j = ($n + 1) / 2; // calculating the value of A to the // power k and X to the power k $aPow = pow($A, $n - $i); $xPow = pow($X, $i); $middleTerm1 = ((float)factorial($n) / (factorial($n - $i) * factorial($i))) * $aPow * $xPow; // calculating the value of A to the // power k and X to the power k $aPow = pow($A, $n - $j); $xPow = pow($X, $j); $middleTerm2 = factorial($n) / (factorial($n - $j) * factorial($j)) * $aPow * $xPow; echo "MiddleTerm1 = " , $middleTerm1,"\n" ; echo "MiddleTerm2 = " , $middleTerm2 ; } } // Driver code $n = 5; $A = 2; $X = 3; // function call findMiddleTerm($A, $X, $n); // This code is contributed by Vishal Tripathi. ?>
Javascript
<script> // JavaScript program to find the middle term // in binomial expansion series. // function to calculate // factorial of a number function factorial(n) { let fact = 1; for (let i = 1; i <= n; i++) fact *= i; return fact; } // Function to find middle term in // binomial expansion series. function findMiddleTerm(A, X, n) { let i, j, aPow, xPow; let middleTerm1, middleTerm2; if (n % 2 == 0) { // If n is even // calculating the middle term i = Math.floor(n / 2); // calculating the value of A to // the power k and X to the power k aPow = Math.floor(Math.pow(A, n - i)); xPow = Math.floor(Math.pow(X, i)); middleTerm1 = Math.floor(factorial(n) / (factorial(n - i) * factorial(i))) * aPow * xPow; document.write("MiddleTerm = " + middleTerm1 + "<br>"); } else { // If n is odd // calculating the middle term i = Math.floor((n - 1) / 2); j = Math.floor((n + 1) / 2); // calculating the value of A to the // power k and X to the power k aPow = Math.floor(Math.pow(A, n - i)); xPow = Math.floor(Math.pow(X, i)); middleTerm1 = Math.floor(factorial(n) / (factorial(n - i) * factorial(i))) * aPow * xPow; // calculating the value of A to the // power k and X to the power k aPow = Math.floor(Math.pow(A, n - j)); xPow = Math.floor(Math.pow(X, j)); middleTerm2 = Math.floor(factorial(n) / (factorial(n - j) * factorial(j))) * aPow * xPow; document.write("MiddleTerm1 = " + middleTerm1 + "<br>"); document.write("MiddleTerm2 = " + middleTerm2 + "<br>"); } } // Driver code let n = 5, A = 2, X = 3; // function call findMiddleTerm(A, X, n); // This code is contributed by Surbhi Tyagi. </script>
MiddleTerm1 = 720 MiddleTerm2 = 1080
Publicación traducida automáticamente
Artículo escrito por Manish_100 y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA