Suma de la serie M/1 + (M+P)/2 + (M+2*P)/4 + (M+3*P)/8……hasta infinito

Encuentra la suma de la serie M/1 + (M+P)/2 + (M+2*P)/4 + (M+3*P)/8……hasta el infinito donde M y P son números enteros positivos.

Ejemplos: 

Input : M = 0, P = 3; 
Output : 6

Input : M = 2, P = 9;
Output : 22

Método: 
S = M/1 + (M + P)/2 + (M + 2*P)/4 + (M + 3*P) / 8……hasta el infinito 
por lo que la solución de esta serie será así
vamos a dividir esta serie en dos partes-
S = (M/1 + M/2 + M/4 + M/8……hasta infinito) + ( p/2 + (2*p)/4 + ( 3*p)/8 + ….hasta el infinito) 
considerémoslo
S = A + B ……..eq(1) 
donde, 
A = M/1 + M/2 + M/4 + M/8… …hasta infinito 
A = M*(1 + 1/2 + 1/4 + 1/8….hasta infinito) 
que es GP de términos infinitos con r = 1/2;
De acuerdo con la fórmula de GP suma de términos infinitos  \frac{a}{1-r}  para r < 1 y 
a es el primer término y r es una razón común, ahora, 
A = M * ( 1 / (1 – 1/2) ) 
A = 2 * M ; 

Ahora para B – 
B = ( p/2 + (2*p)/4 + (3*p)/8 + ….hasta el infinito) 
B = P/2 * ( 1 + 2*(1/2) + 3*(1/4) + ……hasta infinito)
es suma de AGP de infinitos términos con a = 1, r = 1/2 y d = 1;
De acuerdo con la fórmula  \frac{a}{1-r}+\frac{dr}{(1-r)^{2}}  donde a es el primer término, 
r es razón común y d es diferencia común, así que ahora,
B = P/2 * ( 1 / (1-1/2) + (1*1/2) / (1- 1/2)^2 ) 
Segundo = P/2 * 4 
Segundo = 2*P ;
poner el valor de A y B en eq(1) 
S = 2(M + P) 

C++

#include <iostream>
using namespace std;
 
int sum(int M, int P)
{
    return 2*(M + P);
}
 
// driver code
int main() {
 
    int M = 2, P = 9;   
    cout << sum(M,P);   
    return 0;
}

Java

// Java Program to finding the
// sum of the series
import java.io.*;
 
class GFG {
     
    // function that calculate
    // the sum of the nth series
    static int sum_series(int M, int P)
    {
        return 2 * (M + P);
    }
 
    // Driver function
    public static void main (String[] args)
    {
        int M = 2;
        int P = 9;
        System.out.println( sum_series(M, P)) ;
    }
}

Python3

# Python3 Program to finding
# the sum of the  series
 
# function that calculate
# the sum of the  series
def sum_series(M, P):
 
    return int(2 * (M + P))
 
# Driver function
M = 2
P = 9
print(sum_series(M ,P))

C#

// C# program to finding the
// sum of the series
using System;
 
class GFG {
     
    // Function that calculate
    // the sum of the nth series
    static int sum_series(int M, int P)
    {
        return 2*(M + P);
    }
 
    // Driver Code
    public static void Main ()
    {
        int M =2;
        int P =9;
         
        Console.Write( sum_series(M,P)) ;
    }
}

PHP

<?php
// PHP program to finding the
// sum of the series
 
// Function that calculate
// the sum of the nth series
function sum($M, $P)
{
    return 2*($M + $P);
}
 
// Driver Code
$M = 2;
$P = 9;
echo sum($M, $P);
 
// This code is contributed by mits
?>

Javascript

<script>
 
// JavaScript program to finding the
// sum of the series
 
// Function that calculate
// the sum of the nth series
function sum_series(M, P)
{
    return 2 * (M + P);
}
 
// Driver code
let M = 2;
let P = 9;
 
document.write( sum_series(M, P));
 
// This code is contributed by splevel62
 
</script>
Producción: 

22

 

Publicación traducida automáticamente

Artículo escrito por Arpit_Dixit y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *